Java Reference
In-Depth Information
<html>
<head>
<title> A Simple Program </title>
</head>
<body>
<hr>
<applet code = "MyFirstApplet.class" width = 350 height = 200 >
</applet>
<hr/>
</body>
</html>
Directory "MyFirstApplet"
The two bolded lines between tags for horizontal lines specify that the bytecodes for the applet are con-
tained in the file
MyFirstApplet.class
. The name of the file containing the bytecodes for the applet is spe-
cified as the value for the
code
attribute in the
<applet>
tag. The other two attributes,
width
and
height
,
define the width and height of the region on the screen that is used by the applet when it executes. These
always have to be specified to run an applet. Here is the Java source code for a simple applet:
import javax.swing.JApplet;
import java.awt.Graphics;
public class MyFirstApplet extends JApplet {
public void paint(Graphics g) {
g.drawString("To climb a ladder, start at the bottom rung.", 20, 90);
}
}
Directory "MyFirstApplet"
You might get the following warning message when you compile this program:
warning: [serial] serializable class MyFirstApplet has no definition
of serialVersionUID
You can safely ignore this. You learn about serializable classes in Chapter 12.