APPLETS

An Applet is a window-based program. they are event driven. an Applet resembles a set of interrupt service routines . an Applet waits until an event occurs.the AWT notifies the applet about an event by calling an event handler that has been provided by the applet.

                  Applets are not executed by the console based java runtime interprets.Rather they are executed by either a web browser or an applet viewer execution of an applet doesn’t begin at main actually few applets even have main methods. The output of an  applet is handled with various awt methods.

 Applet class
Applet provides all necessary support for applet execution such as starting & stoping.it also provides methods that load and display images audio clips etc.applet extends the awt class panel inturn panel extends container which extends component.

Applet skeleton: When an applet begins the awt calls the following methods in the sequence.

 

init( ):
The init() method is the first method to be called.This is where you should initialize variables.this method is called only once during the runtime of your applet.

sart( ):
The start method is called after init( ).it is also called to restart an applet after it has been stopped. If a user leaves a webpage and comes back the applet resumes execution at start( ).

paint:
The paint() method is called each time your applet’s output must be redrawn,This situation can occur for several reasons.

     Ex
The window in which the applet is running may be over written by another window and then uncovered.The paint( ) method has one parameter of type graphics.

stop( ):
The stop()method is called when a webbrowser leaves the html document containing the applet.

 

 

destroy:
This method is called when the environment determines that your applet needs to be removed completely from memory.

update( ):
            This method is called when your applet has requested that a portion of its window be redrawn. this method calls the paint method.

drawstring:
it is used to print the message in the given x and y co-ordinates.
Syn:    drawString(string,x,y).

setBackground( ):      To set the Background color of an applet
Syn:    setBackground (Color.color);

setForeground( ):      To set the foreground color of an applet.
Syn:    setForeground (Color.color);