You are on page 1of 14

Fundamentals of Applets in Java

Anoop R S
Contents
1. Applets

2. Types of applet

3. Difference between applet and application

4. Life-cycle of an applet

2 Applets in Java-Slide prepared and presented


by Anoop R S
Applets
 A Java program that runs on the Internet.
 Applet programs are run on the client side of the network
 Special type of software called web browsers are used.

3 Applets in Java-Slide prepared and presented


by Anoop R S
Types of applets
 There are basically two types of applets.
 Local applet
 Remote applet
 Local applets are developed locally and run on the same
computer.This applet does not need any Internet
connectivity to run.
 Remote applets are developed and run on a remote
computer.It needs Internet connection to run the remote
applet

4 Applets in Java-Slide prepared and presented


by Anoop R S
Difference between Applet and Application

5 Applets in Java-Slide prepared and presented


by Anoop R S
Application Applet
Difference
Applications between
are stand-alone Applet andweb
Applets need application
browsers to run
programs that can be run
independently without having to
use a web browser.

Java applications have full access to Applets do not have permission to


local file system access the files in local computer
It requires a main() Applets do not have any main()
method for its execution. method
Application can run the programs Applet cannot run the programs in
from the local computer the local system

6 Applets in Java-Slide prepared and presented


by Anoop R S
Life cycle of applet

 The life cycle of an applet consists of four stages.


1. New born state(initialization state)
2. Running State
3. Idle State(stopped state)
4. Dead or destroyed state

7 Applets in Java-Slide prepared and presented


by Anoop R S
New born state
 New born state
 During this state,an applet is initialized. At this stage, the
background colour is set,font is selected and assigned.
This stage occur only once in the life cycle of an applet.It
is attained by invoking a built-in method init().
 The syntax of this method is:
public void init()
{
Statement
}

8 Applets in Java-Slide prepared and presented


by Anoop R S
 Running State
 During this state,an applet begins to execute
 .This is attained using a method called start()
 .The method start() is invoked when an applet is loaded or
reloaded.
 The syntax of the method start() is:
 
public void start()
{
Statements
}
9 Applets in Java-Slide prepared and presented
by Anoop R S
 The components that are to be displayed on the applet
screen can be designed using the method named paint().
 This method has an object of the class Graphics as the
argument.
 The syntax of this method is:
public void paint(Graphics g)
{
Statements
}

10 Applets in Java-Slide prepared and presented


by Anoop R S
 Idle State
 During this state,applet leaves the browser.
 It is done by using the method named stop( ) 
 This method is called when a web browser leaves the
HTML document containing the applet

11 Applets in Java-Slide prepared and presented


by Anoop R S
 Dead or destroyed state
 This state occurs when an applet complete leaves from
memory.
 During this state, a method named destroy() is invoked.

12 Applets in Java-Slide prepared and presented


by Anoop R S
Graphical representation

13 Applets in Java-Slide prepared and presented


by Anoop R S
14 Applets in Java-Slide prepared and presented
by Anoop R S

You might also like