• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 36. Developing Java Applets > Life Cycle of an Applet

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.");
  }
  public void start()
  {
    System.out.println("Applet started.");
  }
  public void paint(Graphics theGraphics)
  {
    theGraphics.drawString("Hello, World!", 0, 50);
    System.out.println("Applet just painted.");
  }
  public void stop()
  {
    System.out.println("Applet stopped.");
  }
  public void destroy()
  {
    System.out.println("Applet destroyed.");
  }
}
					

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint