[java]
package com.spl.applet;
import java.applet.Applet;
import java.awt.Graphics;
public class AppletSkeleton extends Applet{
/*called when applet is terminated.This is the last method execution*/
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
//perform shutdown activities
}
//called first
@Override
public void init() {
// TODO Auto-generated method stub
super.init();
//initialization
}
/*called second,after init().Also called whenever the applet is restarted*/
@Override
public void start() {
// TODO Auto-generated method stub
super.start();
//start or resume execution
}
//called when the applet is stopped
@Override
public void stop() {
// TODO Auto-generated method stub
super.stop();
//suspends execution
}
//called when an applet's window must be restored
public void paint(Graphics g)
{
//redisplay contents of window
}
}
[/java]
When an applet begins,the following methods are called:
1)
init(): The init() method is the first method to be called.This is where you should initialize variables.init() method is called only once during the run time of your applet.
2)
start(): The start() method is called after init(). It is also called to restart an applet after it has been stopped. The init() is called once, where as start() is called each time when an applet's HTML document is displayed onscreen.
3)
paint(): The paint() method is called each time your applet's output must be redrawn. The
paint() method is also called when the applet begins execution.The paint() method has one parameter of type Graphics.
When an Java Applet is terminated,the following methods are called
1)
stop(): The stop() method is called when a web browser leaves the HTML document containing the applet when goes to another page.
2)
destroy(): The destroy() method is called when an environment determines that your applet needs to be removed completely from memory. The
stop() method is always called before destroy().
Output
When compile the code following is the result will be displayed.