public class FirstApplet extends Applet implements ActionListener { public void actionPerformed (ActionEvent e) { } // actionPerformed } // End of FirstApplet |
This is an example of a stub class. A stub class has the basic outline for a class but no real content. In this case the definition must contain a stub definition of the actionPerformed() method, which is part of the ActionListener interface. After entering this, compile and run the program. It should compile correctly, but it won't do anything because it doesn't contain any executable code.
public class FirstApplet extends Applet implements ActionListener { private Button clickMe; // The button public void init() { } // init() public void actionPerformed (ActionEvent e) { } // actionPerformed } // End of FirstApplet |
Recompile the program and run it again. It should compile correctly, but it still won't really do anything. But you've accomplished a lot, because you've now correctly coded the basic structure of the program.
Hopefully, going through this exercise has illustrated some of the advantages of the stepwise refinement approach to writing Java code.