Ch5 Applet, AWT, Event and Swing Programming
Ch5 Applet, AWT, Event and Swing Programming
-Disadvantages:-
v. It cannot read certain system properties.
vi. It cannot read and write ordinary files on the execution host.
- Applet Life Cycle:-
- Applet life cycle has 5 methods init(),start(),stop(), paint() and destroy().
1) init() :- it is the first method.
-this method is intended for whatever initialization is needed for your applet.
-it is automatically invoked by the system when java first launches the applet.
- It typically performs the task such as read parameters, load images etc.
- It is invoked only once.
- public void init()
{
------------
-------------------
Action
}
2) Start() : Applet enters the running state when the system calls the start() method of Applet class.
- This occurs automatically after the applet is initialized .
- It is also called whenever the user returns to the page containing the applet after other pages.
- public void start()
{
-----------
---------
Action
}
3) Stop() : the stop() method stops the execution of the applet .An applet turns into idle state, when it is
stopped from running .This method is automatically called when the user moves off the page on which the
applet sits or when moving from one tab to another in the browser.
- - public void stop()
{
-----------
---------
Action
}
- 4) destroy() :- An applet is said to be dead when it is removed from memory.
- This occurs automatically by invoking the destroy() method when we want to quit the
browser.
- An applet is said to be dead when it is removed from memory .
- The destroy() method contains code release the resources such as thread, graphics
objects.
- public void destroy()
{
-----------
---------
Action
}
- 5) paint() :- the paint() method is called each time an AWT- based applets output must
be redrawn.
- Paint() is also called when the applet begins execution.
- The paint() method has one parameter of type graphics .
- This parameter will contain the graphics context ,which describe the graphics
environment in which the applet is running.
- public void paint(Graphics g)
{
-----------
---------
}