JavaApplets
JavaApplets
Java applets
02/26/25 2
Introduction
Java applets are one of three kinds of Java
programs:
An application is a standalone program that can be
invoked from the command line.
An applet is a program that runs in the context of a
browser session.
A servlet is a program that is invoked on a server
program, and it runs in the context of a web server
process.
02/26/25 3
Applets, web page, client, server
Applets are programs stored on a web server,
similar to web pages.
When an applet is referred to in a web page
that has been fetched and processed by a
browser, the browser generates a request to
fetch (or download) the applet program, then
executes the applet program in the browser’s
execution context on the client host.
02/26/25 4
Applet Execution - 2
Life Cycle of an Applet:
init: This method is intended for whatever initialization
is needed for an applet.
start: This method is automatically called after init
method. It is also called whenever user returns to the
page containing the applet after visiting other pages.
stop: This method is automatically called whenever the
user moves away from the page containing applets.
This method can be used to stop an animation.
destroy: This method is only called when the browser
shuts down normally.
Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html /
02/26/25 5
Applet Execution - 3
The applet is running and rendered on
the web page.
Every Applet needs to implement one of
more of the init(), the start( ) and the
paint( ) methods.
At the end of the execution, the stop( )
method is invoked, followed by the
destroy( ) method to deallocate the
applet’s resources.
02/26/25 6
Applet Security
Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html/
02/26/25 7
Summary
An applet is a Java class
Its code is downloaded from a web server
It runs in the browser’s environment on the client host
It is invoked by a browser when it scans a web page and
encounters a class specified with the APPLET tag
For security reason, the execution of an applet is
normally subject to restrictions:
applets cannot access files in the file system on the client host
Applets cannot make network connection exception to the
server host from which it originated
02/26/25 8
Displaying Graphics in Applet