Applets life cycle


Applet life cycle means the various states through which applet passes during its object creation and removal. Each state is a method. There are total five states (methods), which are shown as :

These methods are called automatically.

init(), start(), stop(), destroy() methods are defined in java.applet.Applet class. paint() method is defined in java.awt.Component class, an indirect superclass of Applet.

init(): The applet starts here. In this method, the applet object is created by the browser, but objects are in inactive states.
This method is suitable to,
Initialize variables, instantiate objects, and colors in GUI etc.
start(): To make the applet object active, the init() method calls start() method, which makes applet active for processor time.

paint(): This method belongs to java.awt.Graphics, which includes many methods of drawing necessary to draw on the applet window. In this method programmer can write his code of what he expects from applet like animation etc. This is similar to runnable state of thread.

stop(): In this method the applet becomes temporarily inactive. An applet can come any number of times into this method in its life cycle and can go back to the active state (paint()).It is similar to the blocked state of the thread.

destroy(): This method is called to end of the life cycle of an applet. It is similar to the dead state of the thread.


init(): Browser called this method at the time of starting the execution. This is called only once in the life cycle.

start(): This method is called by the init() method, a number of times in the life cycle , to make the applet active.

paint(): This  method is called by the start() method, number of times in the execution.

stop(): This method is called to inactivate the applet. This method is called number of times in the execution.

destroy(): This method is called to close the applet, called only once in the life cycle.


Related topics

Please use contact page in this website if you find anything incorrect or you want to share more information about the topic discussed above.