In the Java Applet, all the methods are called sequentially. The sequences of the methods are
This is called life cycle of the applet.
import java.awt.*;
import java.applet.*;/*<applet code=" BasicApplet " width=300 height=100></applet>*/
public class BasicApplet extends Applet
{
public void init() {}
public void start() {}
public void paint(Graphics g) {}
public void stop() {}
public void destroy() {}
}
All the function is mandatory to run an Applet but only required will be overridden by the user.
import java.applet.*;
import java.awt.*;/* <applet width=400 height=200 code="AppletOne.class"></applet> */
public class AppletOne extends Applet
{
public void paint(Graphics g)
{
g.drawString("Tutorial At Home",100,100);
}
}
To Run this program
Every program of applet should inherit from the super class Applet. We can also show the status bar in the window by using the method showStatus(). To runtime drawing in the applet window we must call the redraw() methods. To draw different shape in applet window we can also use the following methods.
drawLine() |
Draw a line from first coordinate to last coordinate. |
drawRect() |
Draw a rectangle by left top coordinate and given width and height. |
fillRect() |
Draw a rectangle by left top coordinate and given width and height. And fill it by a specified color. |
drawRoundRect() |
Draw a rounded rectangle by left top coordinate and given width and height. |
fillRoundRect() |
Draw a rounded rectangle by left top coordinate and given width and height. And fill it by a specified color. |
drawOval() |
Draw a circle or Oval by left top coordinate and given width and height. |
fillOval() |
Draw a circle or Oval by left top coordinate and given width and height. And fill it by a specified color. |
drawPolygon() |
Draw a polygon by a collection of coordinate. |
setForeground( ) |
Set the foreground color. |
setBackground( ) |
Set the background color. |