Applet life cycle?

Applet life cycle: Every java applet inherits a set of default behaviours from the applet class. as a result, when an a...

Applet life cycle:

Every java applet inherits a set of default behaviours from the applet class. as a result, when an applet is loaded it undergoes a series of charged in its state.

The applet states include:

 Born (or) initialization state.

 running state.

 idle state.

 dead (or) destroyed state.

life cycle of applets

Initialization state:

Applet enters the initialization state when it is first loaded. This is achieved by calling the init() method of applet class. The applet is born. At this stage, we may do the following if required.

 create objects needed by the applet
 set up initial values
 load images or fonts
 set up colours

The initialization occurs only once in the applets life cycle. To provide any of the behaviors mentioned above, we must override the init method.

public void init()
{
----------
---------(action)
}

Running state:

Applet enters the running state when the system calls the start( ) method of applet class. This occurs automatically after the applet is initialized. Starting can also occur if the applet is already “stopped” (idle) state.  For example, we may leave the webpage containing the applet temporarily to another page and return back to the page. This again starts the applet running. Note that, unique init() method, the start() method may be called more than once. We may override start() method to create a thread to control the applet.

public void start()
{
----------
---------
--------(action)
}

Idle (or) stopped state:

An applet becomes idle when it is stopped from running. Stopping occurs automatically when we leave the page containing the currently running applet. We can also do so by calling the stop () method explicitly. If we use a thread to run the applet, then we must use stop() method to terminate the thread. We can achieve this by overriding the stop() method.

public void stop()
{
---------
----------
---------(action)
}

Dead state:

An applet is said to be dead when it is removed from memory. This occurs automatically, by invoking the destroy() method when we quite the browser. Like initialization, destroying stage occurs only once in the applets life cycle. If applet has created any resources, like threads, we may over ride the destroy() method to clean up these resources.

public void destroy()
{
----------
----------(action)
}

Display state:

Applet moves to the display state whenever it has to perform some output operations on the screen. This happens immediately after the applet enters into the running state. The point () method is called to accomplish this task. Atmost every applet will have a point() method.
We must therefore over ride this method if we want anything to be displayed on the screen.

public void point(Graphics g)
{
-----------
------------(display statements)
}

It is to be noted that the display state is not considered as a part of the applets life cycle.

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item