0
6.9kviews
Write a short note on Life Cycle of Applet.

Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology

Marks: 5 M

Year: May 2014, May 2015

1 Answer
0
102views
  • Every Java applet inherits a set of default behaviors from the Applet class. As a result, when a applet is loaded it goes through a series of change in its states as shown in figure below:

enter image description here

  • The applet states include:
    • Initialization state
    • Running state
    • Idle state
    • Destroyed state

1) Initialization State:

  • Applet enters the initialization state when it is first loaded. This is achieved by calling the init() method of applet class. The applet is born. At this stage, we may do the following , if required:
    • Create objects needed by the Applet
    • Set up initial values
    • Load images or fonts
    • Set up colors
  • The initialization occurs only once in the applet’s life cycle. To provide any of the behaviours mentioned above, we must override the init() method.

    public void init()

    {

    ………//action

    }

Running State

  • Apple enters the running state when the system calls the start() method of Applet class.
  • This occurs automatically after the applet is initialized. Starting can also occur if the applet is already in ‘Stopped”(idle) state. For example, we may leave the web page containing the applet temporarily to another page and return back to the page.
  • This again starts the applet running. Unlike init(), start() method can be called more than once. We may override the start() method to create a thread to control the applet.

    public void start()

    {

    ………//action

    }

2) Idle or Stopped State

  • An applet becomes idle when it is stopped from running.
  • Stopping occurs automatically when we leave the page containing the current running applet.
  • We can also do so by calling the stop() method explicitly. If we use a thread to run the applet, then we must use stop() method to terminate the thread.
  • We can achieve this by overriding the stop() method:

    public void stop()

    {

    ……//action

    }

3) Dead State

  • An applet is said to be dead when it is removed from memory.
  • This occurs automatically by invoking the destroy() method when we quit the browser.
  • Like initialization, destroying stage occurs only once in the applet’s life cycle. If the applet has created any resources, like threads, we may override the destroy() method to clean up these resources.

    Public void destroy()

    { …….//action}

Please log in to add an answer.