Professional Documents
Culture Documents
Practical 12
Practical 12
Advantage of Applet
o It works at client side so less response time.
o Secured
o It can be executed by browsers running under many platforms, including Linux,
Windows,Mac Os etc.
Drawback of Applet
• Plug-in is required at client browser to execute applet.
java.applet.Applet:
java.awt.Component class :
The Component class provides 1 life cycle method of applet.
Syntax:
public void init()
{
//Statements
}
2. Running State
• After initialization, this state will automatically occur by invoking the start method
of applet class which again calls the run method and which calls the paint method.
• The running state also occurs from idle state when the applet is reloaded.
• This method may be called multiples time when the Applet needs to be started or
restarted.
• For Example if the user wants to return to the Applet, in this situation the start
Method() of an Applet will be called by the web browser and the user will be back on
the applet.
• In the start method user can interact within the applet.
Syntax:
public void start()
{
//Statements
}
3. Idle State
• The idle state will make the execution of the applet to be halted temporarily.
• Applet moves to this state when the currently executed applet is minimized or
when the user switches over to another page.
• At this point the stop method is invoked.
• From the idle state the applet can move to the running state.
• The stop() method can be called multiple times in the life cycle of applet Or called
at least one time.
• For example the stop() method is called by the web browser on that time When the
user leaves one applet to go another applet
Syntax:
public void stop()
{
//Statements
}
4. Dead State
• When the applet programs terminate, the destroy function is invoked which makes
an applet to be in dead state.
• The destroy() method is called only one time in the life cycle of Applet like init()
method.
Syntax:
public void destroy()
{
//Statements
}
5. Display State
• The applet is said to be in display state when the paint method is called.
• This method can be used when we want to display output in the screen.
• This method can be called any number of times.
• paint() method is must in all applets when we want to draw something on the
applet window.
• paint() method takes Graphics object as argument
Syntax:
public void paint(Graphics g)
{
//Statements
}
E. A Simple Applet :
Now we are going to see the simple program of print hello world using applet.
F. Parameter in Applet
We can get any information from the HTML file as a parameter. For this purpose,
Applet class provides a method named getParameter().
Syntax:
public void start()
{
//Statements
}
Conclusion :
In this practical I learnt about applet , the life cycle of applet , how to run
applet and programs related to applets.