0% found this document useful (0 votes)
10 views7 pages

Applet Java 5

Uploaded by

ajjugamer171
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
10 views7 pages

Applet Java 5

Uploaded by

ajjugamer171
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

JAVA

UNIT-V
Applets, local and remote applets, applets VS
applications, writing applets, applets life cycle,
creating an executable applet, designing a web page,
applet tag, adding applet to HTML file,
running the applet, passing parameters to applets,
aligning the display, HTML tags & applets,
getting input from the user interface.

Applets:
An applet is a special Java program that runs in a browser
enabled with Java technology (JRE) that can be downloaded
from the internet and run. An applet is typically embedded
inside a HTML page and runs in the context of a browser. An
applet is designed to run remotely in the client browser, so
there are some restrictions on it. The applet can't access
system resources on the local computer. Applets are used to
make the web site more dynamic and entertaining. An applet
must be a subclass of the java.applet.Applet class. The Applet
class provides the standard interface between the applet and
the browser environment.
Features of Java Applet :
It requires a Java-supported web browser for its execution.
All the Java applets are a sub-class of the
java.applet.Applet class.
main() method is not required
it follows this sequence while executing methods : init(),
start(), paint() and then other methods.
Termination of a Java applet is done by stop() and
destroy() methods.
It is used to display dynamic content.
JAVA
UNIT-V
local and remote applets:
Local Applet is written on our own, and then we will embed
it into web pages. Local Applet is developed locally and
stored in the local system. A web page doesn't need the
get the information from the internet when it finds the
local Applet in the system. It is specified or defined by the
file name or pathname. There are two attributes used in
defining an applet, i.e., the codebase that specifies the
path name and code that defined the name of the file that
contains Applet's code.
<applet
codebase = "tictactoe"
code = "FaceApplet.class" width = 120
height = 120> </applet>

A remote applet is designed and developed by another


developer. It is located or available on a remote computer
that is connected to the internet. In order to run the applet
stored in the remote computer, our system is connected to
the internet then we can download run it. In order to
locate and load a remote applet, we must know the
applet's address on the web that is referred to as Uniform
Recourse Locator(URL).
<applet
codebase = "http://www.myconnect.com/applets/"
code = "FaceApplet.class"
width = 120
height =120>
</applet>
JAVA
UNIT-V
applets VS applications
Java Applet:
1.A Java Applet is a program that runs on a Java-
supported web browser. Java applets are used to
implement in HTMLs.
2.For executing a Java applet, we do not need a main()
method, instead for Java applets we have methods such as
init(), start(), and paint() to initiate the program.
3.Java applets are compiled with the help of Java
Compiler and executed with the help of a Java-supported
web browser.
4.For executing a Java applet, we do not need to save it in
the file system.
5.It just needs a Java-supported web browser to execute.

Java Application
1.A Java Application is a Java program that runs on the
system with the help of JVM.
2.For executing a Java application we require a main()
method that calls other methods or it has other
instructions.
3.Java applications are compiled and executed with the
help of the Java compiler (Java virtual machine).
4.For the execution of Java Application, it needs to be
saved in the file system of the computer.
5.It needs JRE (Java Runtime Environment) to execute.
JAVA
UNIT-V
Life Cycle Of An Applet :
These are the different stages involved in the life cycle of
an applet.
Initialization State
Running State
Idle or stopped state
Dead State
Display State
JAVA
UNIT-V
Initial ization State
The l ife cycl e of an appl et begins when the appl et i s f i rs t l oaded
into the browser and cal l ed the i ni t( ) method . A nd the i ni t( )
method is cal l ed exactl y once i n an appl et's l i f e when appl et i s
first l oaded. Basical l y t he pur pos e of t he ini t( ) method i s to read
the PARAM tag in the HTML f i l e. It is r etri ev i ng the parameters i n
the param tag.

Syntax

publ ic void init()


{
Statements
}

Running State
This state is the second s tage of the appl et l i f e cycl e. A f ter
initial ization, this stat e wi l l automat i cal l y occur by i nv oki ng the
start method of the appl et c l as s whi ch agai n cal l s the run m ethod
and which cal l s the pa i nt method. And i t can occur f rom the Id l e
State when the appl et is r el oaded. Thi s method runs mul ti pl e
times.

Syntax

publ ic void start()


{
Statements
}
JAVA
UNIT-V
Idl e State
This state is the third st age of t he applet li f e cycl e; another name
for it is Stopped state. There ar e t wo c onditi ons when an appl et
moves to this state; when the currentl y ex ecuted appl et i s
minimized or when the us er swi tches t o anot her pag e. A t thi s poi nt
the stop method is inv oked. It i s cal l ed at l eas t once when the
browser l eaves the web page when we mo v e f rom one pag e to
another. This method i s cal l ed only i n the Ru nni ng State and can
be cal l ed any number of ti mes .

Syntax

publ ic void stop()


{
Statements
}

Dead State
This state is the fourt h s tage of the appl et l i f e cycl e. When the
appl et program terminates , the des troy f uncti on i s i nv oked whi ch
makes an appl et to be i n the Dead State. Thi s s tage occurs when
the destroy() method is c al l ed. And thi s method i s cal l ed onl y one
time in the whol e l ife cycl e.

Syntax

publ ic void destroy()


{
Statements
}
JAVA
UNIT-V
Displ ay State
After the paint method is c al l ed the applet i s s ai d to be i n the
Displ ay State. The appl et i s s ai d t o be i n the Di s pl ay State when
the paint method is cal led. Thi s method can b e us ed when we want
to displ ay o utput in the s creen.paint( ) method . It i s requi red i n al l
appl ets when we want to dr aw s omethi ng on the appl et wi ndow.
And the paint method takes a Graphi cs obj ect as an argument.

Syntax

publ ic void paint(Graphi cs g)


{
Statements
}

You might also like