2
Objectives
On completion of this period, you would be able
to learn
• Life cycle of an applet
3
Recap
In the last class, you have studied about applet
classes and applet architecture
•Applet class hierarchy
•Applet methods
•Applet architecture
4
Applet Life Cycle
•When an applet is loaded, it undergoes a series
of changes in its state
•The applet states include
•Born or initialization state
•Running state
•Idle state
•Dead or destroyed state
5
Applet Life Cycle contd..
•The changes in state of applet life is shown in
the following state transition diagram
Born
Running Idle
Dead End
Stopped
Destroyed
Exit browser
Begin
(Load applet)
Initialization
Display
paint()
start() stop()
start() destroy()
Fig. 57.1 Applet state transition diagram
6
•Initialization state
•Applet enter this state when it is first loaded
•This is achieved by calling init() method
•The init( ) method is the first method to be called
• Initialize variables in this method
•This method is called only once during the life time of
your applet
Applet Life Cycle contd..
7
Applet Life Cycle contd..
•Running state
•Applet enters into running state when it calls start()
method
•The start( ) method is called after init( )
•It is also called to restart an applet after it has been
stopped
•Where as init( ) is called only once, start() method
may be called any number of times
•When a user leaves a web page and comes back, the
applet resumes execution
8
•Idle or stopped state
•Applet becomes idle when it is stopped
•Stopping automatically occurs when we leave
the page containing the current applet
•We can achieve this by calling stop() method
•stop() method suspends applet execution until
the user clicks on it
Applet Life Cycle contd..
9
Applet Life Cycle contd..
•Dead state
•Applet is said to be dead when it is removed
from memory.
•This occurs by calling destroy() method
•The destroy() method perform shutdown
activities
•It also removes the applet from the memory
10
•Display state
•Applet moves to the display state whenever it has to
perform some output operation on the screen
•The paint() method is called to accomplish this task
•Paint() method does absolutely nothing
•We have to override this method to display the
required graphics
Applet Life Cycle contd..
11
Summary
In this class you, have learnt
•Applet life cycle has different state
–Born
–Running
–Idle
–Dead
12
Summary contd..
The method useful for these state change
–init()
–start()
–stop()
–paint()
–destroy()
13
Quiz
1.Which method in the life cycle of an applet
called only once
a)stop()
b)start()
c)init()
d)destroy()
14
Quiz contd..
2. Which method in the life cycle of an applet
removes the applet from the memory
a)stop()
b)start()
c)init()
d)destroy()
15
Frequently Asked Questions
1. Write about the life cycle of an applet