1 of 11

Application Development using JAVA

Hierarchy & Life cycle of Applets

Smt.M.Jeevana Sujitha

Assistant Professor

Department of Computer Science and Engineering

SRKR Engineering College, Bhimavaram, A.P. - 534204

2 of 11

OBJECTIVES

The Objectives of this lecture are

  • To learn about hierarchy of applets.
  • To learn about life cycle of an applet.

3 of 11

Hierarchy of Applet

  • java.lang.Object
  • java.awt.Component
  • java.awt.Container
  • java.awt.Panel
  • java.awt.Applet

4 of 11

Life cycle of Applet

5 of 11

Life cycle of Applet

  • The applet states include
  • Initialization state
  • Running state
  • Idle or stopped state
  • Dead state
  • Display state

6 of 11

Life cycle of Applet

  • Initialization state: Applet enters the initialization state when it is first loaded.
  • It is achieved by calling the init() method of Applet class.
  • The initialization occurs only once in the life cycle of applet.
  • At initialization state we can setup initial values, load images and setup colors.

Syntax:

public void init()

{

Action

}

7 of 11

Life cycle of Applet

  • Running state: Applet enters the Running state when the system calls the start() of Applet class.
  • This occurs automatically after the applet is initialized.
  • The start() method is called more than once. Syntax:

public void start()

{

Action

}

8 of 11

Life cycle of Applet

  • Idle or stopped state: An applet becomes idle when it is stopped from running.
  • Stopping occurs automatically when we leave the page containing the currently running applet.
  • We can also stop the currently running applet by using stop() method explicitly.

Syntax:

public void stop()

{

Action

}

9 of 11

Life cycle of Applet

  • Dead state: An applet is said to be dead when it is removed from memory.
  • This occurs automatically when we quit from the browser or by calling destroy() method.
  • Like initialization destroying stage occurs only once in the applet life cycle.
  • We may override the destroy() method to cleanup the resources.

Syntax:

public void destroy()

{

Clean up code

}

10 of 11

Life cycle of Applet

  • Display state: An applet moves to the display state whenever it has to perform some output operations on the screen.
  • This happens immediately after the applet enters into the running state.
  • The paint() method is called to accomplish this task.

Syntax:

public void paint(Graphics g)

{

Display statements

}

11 of 11

THANK YOU