Hello world applet
To create an hello world applet you need three files; a .java, .class and a .html file.
import java.awt.Graphics;
public class HelloWorld extends java.applet.Applet {
public void init() {
resize(200,25);
}
public void paint(Graphics g) {
g.drawString("Hello world!", 75, 15);
}
}
The resize(200,25) command sets the width to 200 pixels and height to 25 pixels.
g.drawString("Hello world!", 75, 15) draws the string "Hello world!" from pixel 75 on the y axis and 15 on the x axis.
When the java file named HelloWorld.java is compiled you need an applet tag to integrate the applet in your html
<html>
<head>
<title>Hello world!</title>
</head>
<body>
<applet code="HelloWorld" width="200" height="25">
</applet>
</body>
</html>
You can also control the width and height of the applet using the width and height tags. You normally use the same specification as your java file.