Java Reference
In-Depth Information
This ensures that if your applet doesn't work, it is almost certainly your code that is the problem, rather than
some problem of Java integration with the browser.
If you have compiled an applet and included it in a web page stored as MyApplet.html in the current
directory that contains the .clas s file, you can execute it by entering the following command:
appletviewer MyApplet.html
So how do you put an applet in a web page?
The Hypertext Markup Language
The Hypertext Markup Language , or HTML as it is commonly known, is used to define a web page. When
you define a web page as an HTML document, it is stored in a file with the extension .html . An HTML
document consists of a number of elements, and each element is identified by tags . The document begins
with <html> and ends with </html> . These delimiters, <html> and </html> , are tags, and each element in
an HTML document should be enclosed between a similar pair of tags between angle brackets. All element
tags are case-insensitive, so you can use uppercase or lowercase, or even a mixture of the two. Here is an
example of an HTML document consisting of a title and some other text:
<html>
<head>
<title>This is the title of the document</title>
</head>
<body>
You can put whatever text you like here. The body of a document can contain
all kinds of other HTML elements, including <B>Java applets</B>.
Note how each element always begins with a start tag identifying the
element, and ends with an end tag that is the same as the start tag but
with a slash added. The pair of tags around 'Java applets' in the previous
sentence will display the text as bold.
</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. 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 are 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 a page and separate one type
of element from another. Another is <center> , which centers the output from the applet.
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:
Search WWH ::




Custom Search