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

Java Applet

Java Applet is a client-side program embedded in webpages to create dynamic content, offering benefits like reduced response time and cross-platform compatibility. The applet lifecycle includes initialization, starting, painting, stopping, and destruction, with specific methods provided for each stage. Additionally, the java.awt.Graphics class allows for image display within applets using the drawImage() method, facilitating applications in games and animations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Java Applet

Java Applet is a client-side program embedded in webpages to create dynamic content, offering benefits like reduced response time and cross-platform compatibility. The applet lifecycle includes initialization, starting, painting, stopping, and destruction, with specific methods provided for each stage. Additionally, the java.awt.Graphics class allows for image display within applets using the drawImage() method, facilitating applications in games and animations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Applet

Applet is a special type of program that is embedded in the webpage to generate the dynamic
content. It runs inside the browser and works at client side.

o It works at client side so less response time.

o Secured

o It can be executed by browsers running under many plateforms, including Linux, Windows,
Mac Os etc.

Hierarchy of Applet

Lifecycle of Java Applet


1. Applet is initialized.
2. Applet is started.
3. Applet is painted.
4. Applet is stopped.
5. Applet is destroyed.
For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle
methods of applet.
1. public void init(): is used to initialized the Applet. It is invoked only once.
2. public void start(): is invoked after the init() method or browser is maximized. It is
used to start the Applet.
3. public void stop(): is used to stop the Applet. It is invoked when Applet is stop or
browser is minimized.
4. public void destroy(): is used to destroy the Applet. It is invoked only once.
java.awt.Component class
The Component class provides 1 life cycle method of applet.
1. public void paint(Graphics g): is used to paint the Applet. It provides Graphics class
object that can be used for drawing oval, rectangle, arc etc.

Displaying Image in Applet


Applet is mostly used in games and animation. For this purpose image is required to be
displayed. The java.awt.Graphics class provide a method drawImage() to display the image.
Sytax: public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
The java.applet.Applet class provides getImage() method that returns the object of Image.
Syntax: public Image getImage(URL u, String image){}
import java.awt.*;
import java.applet.*;
public class DisplayImage extends Applet {
Image picture;
public void init() {
picture = getImage(getDocumentBase(),"sonoo.jpg");
}
public void paint(Graphics g) {
g.drawImage(picture, 30,30, this);
}

You might also like