This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Thursday, March 2, 2023

Explain the life cycle of applet with a block diagram.

 The life cycle of an applet refers to the different stages that an applet goes through during its execution. An applet has a well-defined life cycle, which consists of several methods that are called by the browser at various stages. 


fig : life cycle of applet

There are five methods of an applet life cycle, and they are:

  1. init(): The init() method is the first method to run that initializes the applet. It can be invoked only once at the time of initialization. The web browser creates the initialized objects, i.e., the web browser (after checking the security settings) runs the init() method within the applet.
  2. start(): The start() method contains the actual code of the applet and starts the applet. It is invoked immediately after the init() method is invoked. Every time the browser is loaded or refreshed, the start() method is invoked. It is also invoked whenever the applet is maximized, restored, or moving from one tab to another in the browser. It is in an inactive state until the init() method is invoked.
  3. stop(): The stop() method stops the execution of the applet. The stop () method is invoked whenever the applet is stopped, minimized, or moving from one tab to another in the browser, the stop() method is invoked. When we go back to that page, the start() method is invoked again.
  4. destroy(): The destroy() method destroys the applet after its work is done. It is invoked when the applet window is closed or when the tab containing the webpage is closed. It removes the applet object from memory and is executed only once. We cannot start the applet once it is destroyed.
  5. paint(): The paint() method belongs to the Graphics class in Java. It is used to draw shapes like circle, square, trapezium, etc., in the applet. It is executed after the start() method and when the browser or applet windows are resized.
In summary, the applet life cycle is a series of stages that occur during the execution of an applet. These stages are controlled by the browser and are important for initializing, starting, running, and terminating the applet.

No comments:

Post a Comment

If you have any doubts, please let me know

Slider Widget