0% found this document useful (0 votes)
29 views3 pages

Module8 Applet

An applet is a small Java program that can be run in a web browser. Applets allow web pages to include dynamic content and interactive elements. An applet has a lifecycle with five main methods: init() for initialization, start() to begin execution, stop() to pause execution, destroy() to terminate the applet, and paint() to draw graphics. Applets can be either local, stored on the user's system, or remote, stored on another connected computer. They are embedded in HTML pages using the <applet> tag.

Uploaded by

Vineet Pathak
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)
29 views3 pages

Module8 Applet

An applet is a small Java program that can be run in a web browser. Applets allow web pages to include dynamic content and interactive elements. An applet has a lifecycle with five main methods: init() for initialization, start() to begin execution, stop() to pause execution, destroy() to terminate the applet, and paint() to draw graphics. Applets can be either local, stored on the user's system, or remote, stored on another connected computer. They are embedded in HTML pages using the <applet> tag.

Uploaded by

Vineet Pathak
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/ 3

Applet

An applet is a small java program which is used to develop web application.


Applet programs can be transported over the internet from one computer to another
and run using the “Applet Viewer” or any web browser that supports Java. An
applet program can perform arithmetic operations, display graphics, play sounds,
accept user input, create animation, and play interactive games.

Types of applet
 Local applet: An applet developed locally and stored in a local system is
known as a local applet.
 Remote applet: A remote applet is that which is developed by someone else
and stored on a remote computer connected to the Internet.

Life cycle of an applet:-


There are five methods of an applet life cycle

 init(): The init() method is the first method to run that initializes the applet.
It can be invoked only once at the time of initialization.
 start(): The start() method contains the actual code of the applet and starts
the applet. It is invoked immediately after the init() method is invoked.
Every time the browser is loaded or refreshed, the start() method is invoked.
 stop(): The stop() method stops the execution of the applet. The stop ()
method is invoked whenever the applet is stopped, minimized, or moving
from one tab to another in the browser, the stop() method is invoked.
 destroy(): The destroy() method destroys the applet after its work is done. It
is invoked when the applet window is closed or when the tab containing the
webpage is closed.
 paint(): The paint() method belongs to the Graphics class in Java. It is used
to draw shapes like circle, square, trapezium, etc., in the applet. It is
executed after the start() method and when the browser or applet windows
are resized.
example:-
import java.applet.*;
import java.awt.*;
class abc extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawRect(100,100,50,70);
g.setColor(Color.green);
g.fillOval(300,300,50,50);
}
}

/* <applet code = “abc.class” width = “500” height = “500”> </applet> */


How to access applet programs in HTML
<html>
<head>
<title> Use of Applet in HTML </title>
</head>
<body>
<applet code = “abc.class” width = “500” height = “500”> </applet> */
</body>
</html>

You might also like