Java Applet Revision
I first posted an entry on this topic back in February 2009. To refresh my memory, I'll just run through the steps of adding a very simple applet to a web page again. The code for the simple applet is as follows:
import javax.swing.JApplet;
import java.awt.Graphics;
public class HelloWorld extends JApplet {
public void paint(Graphics g) {
g.drawRect(0, 0,
getSize().width - 1,
getSize().height - 1);
g.drawString("Hello world!", 5, 15);
}
}
This was borrowed from the old (pre-Oracle) Java tutorial. A slightly more sophisticated version is offered in the current Java Applet tutorial.
The code to include the applet in a web page might be:
<html>
<body>
<applet code="HelloWorld.class"
width="150" height="50">
</applet>
</body>
</html>
And the page might look like this.
Comments