«^»
4.6. The lifecycle of a Java applet

The HelloJApplet applet just overrides the paint method. Most applets do something more involved than just painting. In order to write any code for an applet you need to be aware of the lifecycle of an applet, i.e., the various stages that an applet goes through from birth to death.

When the bytecodes of an applet are loaded (or reloaded), the init method of the applet is executed. Then the applet's start method is executed. This method is also re-executed when the user comes back to the WWW page associated with the applet after having visited another page. Whenever the user leaves this page, the stop method is executed. Finally, the destroy method is executed if the WWW browser has to unload the applet.

By default, the class java.applet.Applet defines methods for init, start, stop and destroy that do nothing, i.e., they have empty bodies. So, if you want to define some actions to take place at the various points in the lifecycle of an applet, you just need to override the appropriate methods.

Overriding the start and stop methods is important for applets which start a new thread.