Every Applet has:
Born state
Running state
Idle state (may or may not)
Dead state
Born State – When the class is executed the init function is
automatically invoked. At this stage an applet is said to be born. This state
is also called initialization state. During the applet life cycle, the born
state occurs only once. The init function is defined within an applet. However,
it can be overridden by the program. This function is used to initialize
instance members, to load the required fonts, to initialize objects, to load
pictures, to load back colors, etc.
Running State – After initialization, this state will automatically
occur by invoking the start method of applet class which again calls the run
method and which calls the paint method. The running state also occurs from
idle state when the applet is reloaded.
Idle State – The idle state will make the execution of the
applet to be halted temporarily. Applet moves to this state when the currently
executed applet is minimized or when the user switches over to another page. At
this point the stop method is invoked. From the idle state the applet can move
to the running state.
Figure 1

Dead State – When the applet programs terminate, the destroy
function is invoked which makes an applet to be in dead state.
Examples of applet programming:
Listing 4 – For printing a message
import java.lang.awt.*;
import java.lang.applet.*;
public class message extends Applet
{
String msg;
void init()
{
msg = “Welcome to applet programming”;
}
public void paint(Graphics g)
{
g.drawString(msg,100,400);
}
}
Listing 5 - For printing the sum of two values
import java.lang.awt.*;
import java.lang.applet.*;
public class message extends Applet
{
int x,y,z;
String sum;
void init()
{
x = 10;
y = 20;
z = x + y;
sum = “The sum is” +String.valueOf(z);
}
public void paint(Graphics g)
{
g.drawString(sum,100,400);
}
}
Listing 6 - For drawing a human face (eyes – black,
ears – pink, face – yellow, lips – red)
import java.lang.awt.*;
import java.lang.applet.*;
public class face extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.yellow);
g.fillOval(150,150,100,100);
g.setColor(Color.black);
g.fillOval(170,170,15,15);
g.fillOval(215,170,15,15);
g.drawLine(200,190,200,210);
g.setColor(Color.red);
g.fillOval(190,220,20,10);
g.setColor(Color.pink);
g.fillOval(135,185,15,25);
g.fillOval(250,185,15,25);
}
}
Since everything has its brighter as well as darker side,
applets also have their own limitations.
Applets do not use the main method for initializing the
execution of the code.
Applets cannot be run independently. They are run inside a
web page using HTML tag.
Applets are restricted from using library files.