Applet Life Cycle

Posted By :Pawan Singh Nagarkoti |27th April 2023

Applet Life Cycle 
Every applet inherits a set of behaviors from the Applet class. As a result, when an applet is loaded, it undergoes the series of changes its state as shown in the figure. The applet life cycle states are below:-
1. initialization state/Born state.
2. Running or active state.
3. Idle or waiting state. 
4. Dead or Destroyed state.

 

1.  Initialization State     
In Applet initialization state is those state when the object is created. Applet has gone the initialization state when its first loaded.

public void init() 
{
...............
...............(Action)
}

2. Running State 
When Applet enters the running state when the system call the start () method of Applet class. In the running state, the process is ready to start. This occurs automatically after the applet initialized. Starting can also occur when the applet is already in "stopped" state. This again starts the applet running. We may override the start() method for creating a thread to control the applet.

public void start() 
{
.............
............
............ (Action and statements)
}


3. Idle or Stopped State
An applet gets idle when it stops executing. Stopping automatically when we leave the page containing the currently running applet. We can also do by calling the stop() method externally. If we use a thread to run an applet, then we must be use stop() method to terminate the thread.

public void stop()
{
.............
............. (Action)
.............
}


4. Dead State 
An applet is said to be destroyed when it is removed from memory. When a state totally destroys it is called dead state. This occurs automatically when the destroy() method is call and when we quit the browser.  initialization and destroying stage occurs only once in the applet's life cycle. If the applet has created threads, we override the destroy() method to clean up these threads. 
public void destroy()
{
................
................ (Action)
................
}


5. Display State
Applet moves to the display state whenever it has to perform all above operations and some output operations on the screen. We must, therefore, override this method if we want to displayed anything on the screen.
public void paint(Graphics g)
{
............
............ (Display statements)
.............
}

 

Infect, the paint() method is defined in the applet class. It is inherited from the component class, a superclass of a applet.
Methods of Applet Life Cycle
There are basically five methods for Applet life cycle.

1. init()
2. start()
3. paint()
4. stop()
5. destroy() 


1. init():- init() method is used for creating a applet object in java. When init() method is defined than this state is called born state.
It is call all method like start(), paint() etc. It is usually declared and initialize variables. 

2. start():- After creating a born state by the init() method. We have need to start this method. And we start is by using start() method. By using the start() method we have gone born state to active state.

3. paint():- For calling the paint() method we have to need to define his predefine method java.awt.Graphics;. By using the paint() method we move to running state to runnable state.

4. stop():- stop() method is used to move the process into waiting state/blocked state.

5. destroy():- destroy() method is used to destroy an applet. When an applet is destroyed this state called dead state.


About Author

Pawan Singh Nagarkoti

Pawan is a highly skilled Frontend Developer with extensive experience in the industry. He stays up-to-date with the latest technologies, including Angular, JavaScript, React JS, HTML5, and CSS3. He has contributed to a diverse range of projects, including Konfer, KRB and Microsite (chatbot and ChatGPT). He consistently strives for excellence and delivers exceptional results in his work. He is passionate about exploring the internet and staying informed about the latest advancements in the ever-evolving world of technology. Pawan's commitment to continuous learning enables him to stay at the forefront of his field and deliver innovative solutions to his clients.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us