Professional Documents
Culture Documents
applet
is
terminated.
This
is
the
last
method
When Applet is created it under goes series of changes in its state. The applet
state include.
1.
2.
3.
4.
The stop( ) method is called when a web browser leaves the HTML document
containing the appletwhen it goes to another page, for example.
When stop( ) is called, the applet is probably running. stop( ) method is also
used to suspend threads that dont need to run.
when the applet is not visible. It can be restarted when start( ) is called if the
user returns to the page.
Dead state or destroy()
An applet is said to be dead when it is removed from memory. This is achieved
by overriding destroy() method.
public void destroy()
{
}
The destroy( ) method is called when the environment determines that applet
needs to be removed completely from memory.
this point, you should free up any resources the applet may be using.
stop( ) method is always called before destroy( ).
Like initialization , destroying stage occurs only once in the applets life cycle.
Display state or paint()
Applet moves to the display state whenever it has to perform some output
operations on the screen.
This happen immediately after the applet enters into the running state. The
paint method is called to accomplish this task.
This is achieved by overriding destroy() method.
public void paint(Graphics g)
{
}
Example
import java.applet.*;
import java.awt.*;
// public void drawString(String message,int x,int y)
/*
<applet code="AppletLifecycle" width=300 height=300>
</applet>
*/
public class AppletLifecycle extends Applet
{
String str = "";
public void init()
{
str += "init; ";
}