1 applets are small applications that are accessed on an internet server, transported over the...
TRANSCRIPT
1
• Applets are small applications that are accessed
on an Internet server, transported over the
internet, automatically installed and run as a
part of web document.
• Applets interact with the user through the AWT,
not through the console based I/O classes.
Applets
2
• Every applet that you create must be a
subclass of Applet, in the java.applet package.
• Applets don’t have a main().
• An applet begins execution when the name of
its class is passed to an applet viewer or the
web browser.
Applets
3
To execute an Applet
• Edit Java source file.
• Compile your program.
• Make an HTML file that contains the tag that
loads the applet.
• Execute the applet viewer, specifying the name
of your applet’s source file.
4
Applet Architecture
• All applets are subclasses of Applet.
• An applet is a window-based program.
• Applets are event driven.
• The user initiates interaction with the applet.
5
Applet class
• Applets override a set of methods that provide the basic
mechanism by which the browser interfaces to the applet
and controls its execution.
• init(), start(), stop() and destroy() – apply to applets and
are defined by Applet.
• Applets override the paint() of the AWT Component class.
This is called when the applet’s output is redisplayed.
6
Life Cycle of an Applet• When an applet begins:-– init() – first method – initializes variables – called
only once.– start() – called after init()- used to restart an
applet – called when an applet’s HTML document is displayed onscreen.
– paint() – called when applet’s output must be redrawn. paint() has one parameter of type Graphics – this will contain the graphics context, which describes the graphics envt in which the applet is executing.
7
Life Cycle of an Applet• When an applet terminates:-
– stop() – called when a web browser leaves the
HTML document containing the applet – when it
goes to another page.
– destroy() – called when the envt determines that
your applet needs to be removed completely
from the memory.
8
Life Cycle of an Applet
9
Applet tag
• Applet tag is used to start an applet from an HTML
document and from an applet viewer.
<Applet code=appletfile Width=w Height=h>
</Applet>
• Code – gives the name of the file containing applet’s
compiled .class file.
• Width & Height size of the applet in pixels.