Java Applet.pptx
Java Applet.pptx
Introduction
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.
Advantage of Applet
• There are many advantages of applet. They are as follows:
• It works at client side so less response time.
• Secured
• It can be executed by browsers running under many plateforms,
including Linux, Windows, Mac Os etc.
Drawback of Applet
• Plugin is required at client browser to execute applet.
Hierarchy of Applet
• Applet is initialized.
• Applet is started.
• Applet is painted.
• Applet is stopped.
• Applet is destroyed.
Lifecycle methods for Applet:
}
myapplet.html
<html>
<body>
<applet code="First.class" width="300" height="30
0">
</applet>
</body>
</html>
To execute the applet by appletviewer tool, write in command prompt:
c:\>javac First.java
c:\>appletviewer First.java
Displaying Graphics in Applet
1.public abstract void drawString(String str, int x, int y): is
used to draw the specified string.
• java.awt.Graphics 2.public void drawRect(int x, int y, int width, int height): draws
class provides many a rectangle with the specified width and height.
methods for graphics 3.public abstract void fillRect(int x, int y, int width, int
programming. height): is used to fill rectangle with the default color and
• Commonly used specified width and height.
methods of Graphics 4.public abstract void drawOval(int x, int y, int width, int
class: height): is used to draw oval with the specified width and
height.
5.public abstract void fillOval(int x, int y, int width, int
height): is used to fill oval with the default color and specified
width and height.
6.public abstract void drawLine(int x1, int y1, int x2, int y2 is
1.public abstract boolean drawImage(Image img, int x, int y,
ImageObserver observer): is used draw the specified image.
2.public abstract void drawArc(int x, int y, int width, int height, int
startAngle, int arcAngle): is used draw a circular or elliptical arc.
3.public abstract void fillArc(int x, int y, int width, int height, int
startAngle, int arcAngle): is used to fill a circular or elliptical arc.
4.public abstract void setColor(Color c): is used to set the graphics current
color to the specified color.
5.public abstract void setFont(Font font): is used to set the graphics
current font to the specified font.
Syllabus completed…..!!!