public class FirstApplet extends Applet implements ActionListener |
This is a more complex class header than the one we used for the HelloWorld or Rectangle classes. But this applet is a more sophisticated program because it interacts with the user. Don't worry at this point if its operations seem a bit magical.
The class header serves the purpose of naming the class FirstApplet, designating its accessibility public, specifying that it is an Applet, and declaring that it implements ActionListener, an interface that allows it to respond to the user's mouse clicks. The header begins the definition of the class, which extends all the way to the last line of the program--the line marked with the //End of FirstApplet comment.
The body of a class definition is a block, as is the body of a method. Note how the statements in the block are indented, and how the braces are aligned and commented. These style conventions serve to make the program more readable.
Following the header is a variable declaration:
private Button clickMe; // The button |
As we will see in more detail in the next chapter, variables are memory locations that can store values. In this case, the Applet object is storing a reference to a Button object.