Académique Documents
Professionnel Documents
Culture Documents
introduction
In todays era of internen, we need to write
web based applications that can be
embedded in a webpage.
For this purpose java introduces another style
of programming called Applet.
What is an applet
An applet is a program that appears embedded in a
web document.
it is meant to be hosted by a web browser, which
provides a home for the applet.
Any applet depends on a java capable browser in
order to run it.
It can also be viewed using a tool called the
appletviewer.
Java applets are embedded in a web page using
HTML.
Applet and Applications
Applets Applications
Appletviewer first.java
Appletviewer trial.html
Applets and HTML
<applet
code=class file name
Codebase=url
Width=n
Height=n
HSPACE=n
VSPACE=n>
</applet>
CODE and CODEBASE
CODE
Code is used to indicate the name of the class file
that holds the current applet.
If code alone is used in the <APPLET> tag, the
class file is searched for is searched for in the
same directory as the HTML file that references
it.
CodeBase
CodeBase is used to indicate pathname where
classes are contained.
HSPACE and VSPACE
The Hspace and Vspace attributes set the
amount of space, in pixels, between an applet
and its surrounding text.
Hspace controls the horizontal space
Vspace controls the vertical space
WIDTH and HEIGHT
These attributes are mandatory and specify
the width and height of an applet in pixel.
Basic applet life cycle
Init()
start()
paint()
stop()
destroy()
Basic applet life cycle
An applet context calls methods in the applet
at appropriate times during the life cycle of
the applet .
To initialize the applet
Whenever the applet is loaded initialization process
occurs by default.
Initialization may contain
creating the objects the applet needs,
loading images or fonts ,
setting up an initial state or
setting up parameters.
To provide the behavior for the initialization of an applet
we have to override the init() method :-
public void init()
{
//code for the init method
}
To start the applet
Starting occurs only after the applet is initialized or
the applet was previously stopped.
Starting can occur several times in an applet’,
lifecycle but initialization occurs only once.
In order to provide startup behavior to the applet we,
override the start() method.
Public void start()
{
//code for start method
}
To make an applet
This is done through the method paint().
This method helps in displaying the text or
drawing an image on to the applet.
It takes an argument , which is the instance of
the java.awt.Graphics class.
Public void paint( Graphics g)
{
//code for paint
}
Paint()
Paint method is invoked automatically by the
applet context only for the first time.
</applet>
Receiving parameters passed by <param> tag