Life Cycle of an Applet

You've seen Applet's paint() method. As you might guess, repainting the screen is only one part of an applet's life cycle. This section shows the various stages of an applet's life and suggests various tasks you might want to undertake at each step. To see these steps in action, compile LifeCycle.java given in Listing 36.4. You can construct an HTML file based on the pattern given in HelloApplet.html—just change the name of the class file.

Code Listing 36.4. LifeCycle.java—Stages in the Life of an Applet
 import java.applet.Applet; import java.awt.Graphics; public class LifeCycle extends Applet { public LifeCycle() { System.out.println("Constructor running..."); } public void init() { System.out.println("This is init."); ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.