Previous | Next | Trail Map | Writing Applets | Overview of Applets


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. The same thing happens when the user iconifies the browser window that contains the applet.

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.

Try this: Iconify this window. Most window systems provide a button in the title bar that lets you do this. (Other terms used instead of "iconify" are "miniaturize" or "close".) You should see "stopping..." and then "starting..." added to the applet output above.

Reloading the Applet

Some browsers let the user reload applets, which consists of unloading the applet and then loading it again. Before an applet is unloaded, it's given the chance to stop itself and then to perform a final cleanup, so that the applet can release any resources it holds. After that, the applet is unloaded and then loaded as described in Loading the Applet, above.

Try this: If you're using the HotJava browser, 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. (It appears that the 1.0beta3 Netscape browser reloads the applet only if its reloaded page has changed. If the page hasn't changed, the browser appears to act as if you temporarily left the page.)

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 | Overview of Applets