Applet Skeleton And Lifecycle

import java.awt.*;
import java.applet.*;

/*
<applet code="AppletSkel" width=300 height=100>
</applet>
*/

public class AppletSkel extends Applet
{
// Called first.

public void init()
{
// initialization
}

/* Called second, after init(). Also called whenever the applet is restarted. */

public void start()
{
// start or resume execution
}

// Called when the applet is stopped.
public void stop()
{
// suspends execution
}

/* Called when applet is terminated. This is the last method executed. */

public void destroy()
{
// perform shutdown activities
}

// Called when an applet's window must be restored.
public void paint(Graphics g)
{
// redisplay contents of window
}
}
When an applet begins, the AWT calls the following methods, in this sequence:

1. init( )
2. start( )
3. paint( )
When an applet is terminated, the following sequence of method calls takes place:
1. stop( )
2. destroy( )

 

init( )

The init() method is called exactly once in an applet's life, when the applet is first loaded. It's normally used to read  parameter tags, start downloading any other images or media files you need, and set up the user interface. Most applets have init() methods.  

start( )

The start() method is called at least once in an applet's life, when the applet is started or restarted. In some cases it may be called more than once. Many applets you write will not have explicit start()methods and will merely inherit one from their super class. A start() method is often used to start any threads the applet will need while it runs.

Paint()

The paint() method is called each time your applet's output must br redrawn.This situation can occur for several reason .For example in which the applet is running may be overwritten by another window and the uncovered or the applet window may be minimized and the then restored. paint() is also called when the applet begins execution .Whatever the cause ,whenever the applet must redraw its output ,paint () is called .The paint() method has one parameter of type Graphics.This parameter will contain the graphics context which describes the graphics environment in which the applet is running.

stop( )

The stop() method is called at least once in an applet's life, when the browser leaves the page in which the applet is embedded. The applet's start() method will be called if at some later point the browser returns to the page containing the applet. In some cases the stop() method may be called multiple times in an applet's life. Many applets you write will not have explicit stop()methods and will merely inherit one from their superclass. Your applet should use the stop() method to pause any running threads. When your applet is stopped, it should not use any CPU cycles.


destroy( )

The destroy() method is called exactly once in an applet's life, just before the browser unloads the applet. This method is generally used to perform any final clean-up. For example, an applet that stores state on the server might send some data back to the server before it's terminated. many applets will not have explicit destroy() methods and just inherit one from their superclass.

0 comments:

Post a Comment

 

learn java programming Copyright © 2011-2012 | Powered by appsackel.org