Applet lifecycle

The following is the life-cycle of an Applet which includes five steps :
 
Step 1: Call init() Method

Step 2: Call start() Method

Step 3: Call paint() Method

Step 4: Call stop() Method

Step 5: Call destroy() Method

init(), start(), stop() and destory() are the methods of java.applet.Applet class and paint() is a method of java.awt.Component class.

init() method is used to initialize the Applet. After this start() method invoked which is used to start the Applet. stop() method stops the Applet and destroy() method destroys the Applet.

When the user leaves the page, for example, to go to another page, the browser stops and destroys the applet. The state of the applet is not preserved. When the user returns to the page, the browser initializes and starts a new instance of the applet. 

paint(Graphics g) is used to paint the Applet with different shapes like circle, triangle, oval, square etc. 

When you refresh or reload a browser page, the current instance of the applet is stopped and destroyed and a new instance is created. 

When the user quits the browser, the applet has the opportunity to stop itself and perform a final cleanup before the browser exits.

More Applet Topics :

No comments: