Introduction to Applet:
- Applet is a one type java program.
- The Applet class is contained in the java.applet package.
- All applets are subclasses of Applet.
- Applet is a java program and it runs in the viewer and browser.
- Here, following is the Applet class hierarchy.
Applet Life Cycle:
- Java applet inherits a set of default behaviours from the Applet class.
- Applet has the following state.
1)Born state
2)Running state
3)Idle and stopped state
4)Dead 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.
o Create objects needed by the applet
o Setup initial values
o Load images or fonts
o Set up colors
- The initialization occurs only once in the applet’s life cycle.
- We must declare init() method in the born state.
public void init()
{
-----------
-----------(Action)
-----------
}
2)Running state:
- Applet enters the running state when the system calls the start() method of Applet class.
- This occurs automatically after the applet is initialized.
- 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.
- Start() method may be called more than once.
public void start()
{
------------
------------(Action)
------------
}
3)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 do so by calling the stop() method explicitly.
- If we use a thread to run the applet, then we use a thread to run the applet, then we must use stop() method to terminate the thread.
public void stop()
{
------------
------------(Action)
------------
}
4)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 life cycle.
public void destroy()
{
------------
------------(Action)
------------
}
5)Display state:
- 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 complete this task.
- Every applet have a paint method.
All Layout:Layouts


No comments:
Post a Comment