Professional Documents
Culture Documents
JAVA APPLETS
TOPICS TO BE COVERED…
1 .1 Concept of Applet Programming
Local and Remote applets
Difference between applet and application
Preparing to write applets
Building applet code
Applet life cycle
Creating an executable applet
1.2 Designing a web page:
Applet tag
Adding applet to HTML file
Running the applet
Passing parameter to applet
1.1 CONCEPT OF APPLET PROGRAMMING
Java supports two types of programming :
1) Application program:
application is a program that runs on
your computer under the operating system of that
Computer.
2) Applet program:
An applet is an application designed to be
transmitted over the Internet and executed by a
Java-compatible Web browser.
APPLET
Applet is a small program that are primarily used in
internet computing, they can be transported over the
internet from one computer to another and run using
applet viewer or java compatible web browser.
Java applet is a java class that you embed in an
HTML page and is downloaded and executed by a
web browser.
Applet can‟t be executed directly .
Browser
or
Applet viewer
VM
Applet
LOCAL APPLET
An applet developed locally and stored in a local system
is known as local applet.
User can write his own applets and embed them into
web pages.
LOCAL APPLET
Local applet
Local computer
REMOTE APPLET
An applet which is developed by someone else and
stored on a remote computer connected to the Internet
is known as remote Applet.
If our system is connected to the Internet, we can
download the remote applet onto our system via
Internet and then run it.
User can thus download an applet from a remote
computer system.
In order to locate and load a remote applet ,we must
know the applet‟s address on web. This address is
known as URL(Uniform Resource Locator).
URL and must be specified in the applet‟s HTML
document as the value of the CODEBASE attribute.
REMOTE APPLET
Internet
Applet Application
Applet is dynamic program Application is static
which is run on browser . program which run using
java interpreter.
Applet do not use the main() Application uses main()
method for initiating the method for execution of
execution of the code. the code.
Applets can not be run Application runs
independently. They must independently using javac
be run under an applet compiler.
viewer or a java compatible
web browser.
DIFFERENCE : APPLET AND APPLICATION
Applet Application
Applets can not read or Application can read write
write files on the web user‟s files on the web user‟s
disk. disk.
Applet can not communicate Application can
with other server on the communicate with other
network. servers on the network.
Applet can not run any Application program can
program from the local run from local computer.
computer.
Applets are restricted from Application program can
using libraries from other use methods of c, c++
languages such as c,c++. libraries.
APPLET CLASS
Java.applet.Applet class is actually a subclass of
java.awt.panel.
Java. applet is smallest package in Java API.
It consists of a single class (applet) and three
interfaces: AppletContext ,AppletStub and
Audioclip.
Applet class contains only a single default parameter
less constructor ,which is not used generally.
Applets are constructed by the run time environment
when they are loaded ,they do not have to be explicitly
constructed.
APPLET CLASS
Java.applet.Applet class is actually a subclass of
java.awt.panel.
Java. applet is smallest package in Java API.
It consists of a single class (applet) and three
interfaces: AppletContext ,AppletStub and
Audioclip.
Applet class contains only a single default parameter
less constructor ,which is not used generally.
Applets are constructed by the run time environment
when they are loaded ,they do not have to be explicitly
constructed.
Applet class contains 21 methods that are used to
display images, play audio files ,respond to events
and obtain information about applet‟s execution
environment ,referred as applet‟s context.
Java.lang.Object
Java.awt.Component
Java.awt.container
Java.awt.panel
Java.applet.Applet
Method Description
Image getImage(URL url): Used to retrieve an Image
identified by URL.
Black 0 0 0
Red 255 0 0
Green 0 255 0
blue 0 0 255
import java.awt.*;
import java.applet.*;
public class Hellojava extends Applet
{
public void paint(Graphics g)
{
g.drawString( “Hello java” ,10,100);
}
}
OUTPUT:
(0,0)
100 Applet’s space
Hello java
10
APPLET LIFE CYCLE
Begin Born
(Local Applet)
stop ( )
start ( )
stopped
Runnin Idle
Display g start ( )
destory( )
paint ( )
Destoryed
Dea End
d
Exit of Browser
INITIALIZATION STATE
Applet enters the initialization state when it is first
loaded. This is achieved by calling the init() method of
Applet class. The applet is born.
Initialization state occurs only once in the applet‟s life
cycle.
We do following at this stage,
<!
----------- Comment section
------------
>
<HEAD>
Head section
Title tag
</HEAD>
<BODY>
Applet tag Body section
</BODY>
</HTML>
HEAD SECTION:
<HEAD>
<TITLE> Welcome to Java Applets
</TITLE>
</HEAD>
</APPLET>
</BODY>
APPLET TAG
( 0,0)
(20,20)
( 60,60)
METHODS OF GRAPHICS CLASS
Methods Description
clearRect( ) Erases a rectangular area of canvas
copyArea( ) Copies a rectangular area of the
canvas to other area.
drawArc( ) Draws a hollow arc.
drawLine( ) Draws a straight line.
drawOval( ) Draws a hollow oval
drawPolygon( ) Draws a hollow polygon.