Program to display life cycle of an Applet.
This program demonstartes the life cycle methods of an Applet. During execution of an applet it goes through different stages these are init( ), start( ), paint( ), stop( ) and destroy( ). When you run this program it will call init( ), start( ) and paint( ) method as shown in output. The remaining two methods stop( ) and destroy( ) are called when applet stops or when it is destroyed respectively.
PROGRAM
C:\>javac AppletLifeCycleDemo.java
C:\>appletviewer AppletLifeCycleDemo.java
PROGRAM
import java.applet.Applet;
import java.awt.Graphics;
public class AppletLifeCycleDemo extends Applet {
String msg = "";
public void init() {
msg += "init( ) -> ";
}
public void start() {
msg += "start( ) -> ";
}
public void paint(Graphics g) {
msg += "paint( )";
g.drawString(msg, 20, 20);
}
public void stop() {
msg += " -> stop( )";
}
public void destroy() {
msg += "-> destroy( )";
}
}
/*
<APPLET CODE="AppletLifeCycleDemo.class" HEIGHT="200" WIDTH="200" >
</APPLET>
*/
OUTPUTC:\>javac AppletLifeCycleDemo.java
C:\>appletviewer AppletLifeCycleDemo.java