/*
    This program demonstrates the life cycle of an applet.

    Use this applet with either a browser or with the appletviewer.

    If you use it with a browser, you need to have the Java console
    visible. (How you make the Java console visible depends on which
    version of which browser you are using.) Have both the browser
    window and the Java console window visible at the same time. Then
    load this applet's html page. Go to another web page and then return
    to this applet's page. Minimize and maximize the browser's window.
    Then close the browser window, but don't terminate the browser (you
    can do that by having another browser window open). As you do these
    steps, you will see when each of the init(), destroy(), start(), stop(),
    and paint() methods are called.

    If you use the appletviewer, have both the appletviewer window and the
    Java console window visible. Minimize and maximize the appletviewer
    window. Partialy cover the appletviewer window and then uncover it. Use
    the appletviewer Applet menu to start, stop, reload, and clone this applet.

    Notice that each instance of this applet is given an "instance number" so that
    you can distinguish messages on the console window from different instances.
*/
import java.applet.Applet;
import java.awt.Graphics;

public class AppletLifeCycle2 extends Applet
{
    private static int instanceCounter = 1;
    private int instanceNumber;

    // Called by the browser when the web page
    // containing this applet is loaded.
    public void init()
    {
       // give this instance of the applet an id number
       // and then increment the static counter
       instanceNumber = instanceCounter++;
       System.out.println(instanceNumber + ": init()");
    }

    // Call by the browser after the init() method
    // every time the web page is visited.
    public void start()
    {
       System.out.println(instanceNumber + ": .start()");
    }

    // Called by the browser when the web page containing
    // this applet becomes inactive.
    public void stop()
    {
       System.out.println(instanceNumber + ": .stop()");
    }

    // Called by the browser when the browser exits.
    // (Actually, this is called when the browser window
    // that is displaying this applet is closed.)
    public void destroy()
    {
       System.out.println(instanceNumber + ": destroy()");
    }

    // Called by the browser when the applet needs
    // to paint its part of the browser window.
    public void paint(Graphics g)
    {
       System.out.println(instanceNumber + ": ..paint()");
    }

    public String getAppletInfo()
    {
       return "Demonstrates an applet's life cycle.";
    }

}//AppletLifeCycle2