Java Reference
In-Depth Information
</body>
</html>
There are two elements that can appear directly within the <html> element, a <head> element and a
<body> element, as in the example above. The <head> element provides information about the
document, and is not strictly part of it. The text enclosed by the <title> element tags that appears
here within the <head> element, will be displayed as the window title when the page is viewed.
Other element tags can appear within the <body> element, and they include tags for headings, lists,
tables, links to other pages and Java applets. There are some elements that do not require an end tag
because they are considered to be empty. An example of this kind of element tag is <hr/>, which
specifies a horizontal rule, a line across the full width of the page. You can use the <hr/> tag to divide
up a page and separate one type of element from another. You will find a comprehensive list of
available HTML tags in the topic I mentioned earlier.
Adding an Applet to an HTML Document
For many element tag pairs, you can specify an element attribute in the starting tag that defines
additional or qualifying data about the element. This is how a Java applet is identified in an <applet>
tag. Here is an example of how you might include a Java applet in an HTML document:
<html>
<head>
<title> A Simple Program </title>
</head>
<body>
<hr/>
<applet code = "MyFirstApplet.class" width = 300 height = 200 >
</applet>
<hr/>
</body>
</html>
The two shaded lines between tags for horizontal lines specify that the byte codes for the applet are
contained in the file MyFirstApplet.class . The name of the file containing the byte codes for the
applet is specified 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 will be used by the
applet when it executes. These always have to be specified to run an applet. There are lots of other
things you can optionally specify, as we will see. Here is the Java sourcecode 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);
}
}
Search WWH ::




Custom Search