Applet in JAVA
An applet is a small Java program that is embedded and ran in some
other Java interpreter program such as
- a Java technology-enabled browser
- Sun’s applet viewer program called appletviewer
Life Cycle
of an Applet:
init: This method is
intended for whatever initialization is needed for an applet.
start: This method is
automatically called after init method. It is also called whenever user returns
to the page containing the applet after visiting other pages.
stop: This method is
automatically called whenever the user moves away from the page containing
applets. This method can be used to stop an animation.
destroy: This method is
only called when the browser shuts down normally.
Simple Java Applet
Code
Hello.java
import
java.applet.Applet;
import
java.awt.*;
public
class Hello extends Applet{
public
void init() {
repaint();
}
public
void paint(Graphics g) {
g.drawString(“Hello
World!”,30,30);
}
}
Hello.html
<html>
<body>
<applet
code=“Hello.class”
width=300height=300>
</applet>
</body>
</html>
Passing Parameters to applet
getParameter(“parameter name”) : takes parameters value.
<param> tag : set the parameter value
e.g
<param name=”msg” value=”Hello Applet”>
</param>
Sample Graphics methods
A Graphics is something you can paint on
g.drawString(“Hello”, 20, 20); Hello





No comments:
Post a Comment