/****************************************************** * Applet used to demonstrate the lifecycle of * an applet. It will not work correctly in IE * becuase of the way that IE calls the applet methods. ******************************************************/ import java.applet.Applet; import java.awt.*; public class Simple extends Applet { // used to store the string that you are going to write // out to the applet StringBuffer buffer; // called when the page that contains the applet is // first visited public void init () { buffer = new StringBuffer(); addItem("initializing... "); } // called just before the page that contains the applet is viewed public void start() { addItem("starting... "); } // called right after the user stops looking at the page that // contains the applet public void stop() { addItem("stopping... "); } // called when the applet is going to be destroyed by the browser // it is up to the browser manufacturer as to when this is called public void destroy() { addItem("destroying... "); } // adds the word to the buffer and forces redraw of the applet area. void addItem(String newWord) { buffer.append(newWord); repaint(); } // method that actually does the redrawing of the applet region public void paint(Graphics g) { g.setFont(new Font("Monospaced", 19, Font.PLAIN)); g.drawString(buffer.toString(),2,30); } }