Previous | Next | Trail Map | Writing Applets | The Anatomy of an Applet


The Life Cycle of an Applet

Below (if you're running a Java-compatible browser) is the Simple applet.

Loading the Applet

You should see "initializing... starting..." above, as the result of the applet being loaded. When an applet is loaded, here's what happens:

Leaving and Returning to the Applet's Page

When the user leaves the page -- for example, to go to another page -- the applet has the option of stopping itself. When the user returns to the page, the applet can start itself again.

Try this: Leave and then return to this page. You'll see "stopping..." added to the applet output above, as the applet is given the chance to stop itself. You'll also see "starting...", when the applet is told to start itself again.

Reloading the Applet's Page

When the user reloads the page, the applet is unloaded and reloaded. So that the applet can release any resources it holds, it's given the chance to stop itself and then to perform a final cleanup. After that, the applet is unloaded and then loaded as described in Loading the Applet, above.

Try this: Look at the standard output to see what happens when you reload this page. You should see "stopping..." and "preparing for unloading..." when the applet is unloaded. (You can't see this in the applet above because the applet is unloaded before the text can be displayed.) When the applet is reloaded, you should see "initializing..." and "starting...", just like when you loaded the applet for the first time.

Quitting the Browser

When the user quits the browser (or whatever application is displaying the applet), the applet has the chance to stop itself and do final cleanup before the browser exits.


Previous | Next | Trail Map | Writing Applets | The Anatomy of an Applet