Java Reference
In-Depth Information
4 public DisplayLabel() {
5 add( new JLabel( "Great!" , JLabel.CENTER));
6 }
7 }
Like JFrame , JApplet is a container that can contain other GUI components (see the GUI
class diagrams in Figure 12.1). The default layout manager for JApplet is BorderLayout .
So, the label is placed in the center of the applet (line 5).
18.1
Is every applet an instance of java.applet.Applet ?
Check
18.2
Is javax.swing.JApplet a subclass of java.applet.Applet ?
Point
18.3 The HTML File and the <applet> Tag
To run an applet, you need to create an HTML file with an <applet> tag for
embedding the applet.
Key
Point
HTML
HTML is a markup language that presents static documents on the Web. It uses tags to instruct
the Web browser how to render a Web page and contains a tag called <applet> that incorpo-
rates applets into a Web page.
The HTML file in Listing 18.2 embeds the applet DisplayLabel.class .
L ISTING 18.2 DisplayLabel.html
<html>
<head>
<title> Java Applet Demo </title>
</head>
<body>
<applet
code = "DisplayLabel.class"
applet class
width = 250
height = 50
</applet>
</body>
</html>
>
An HTML tag is an instruction to the Web browser. The browser interprets the tag and
decides how to display or otherwise treat the subsequent contents of the HTML document.
Tags are enclosed inside brackets ( < > ). The first word in a tag, called the tag name , describes
tag functions. A tag can have additional attributes, sometimes with values after an equals sign,
which further define the tag's action. For example, in the preceding HTML file, <applet> is
the tag name, and code , width , and height are attributes. The width and height attributes
specify the rectangular viewing area of the applet.
Most tags have a start tag and a corresponding end tag . The tag has a specific effect on the
region between the start tag and the end tag. For example, <applet...>...</applet> tells
the browser to display an applet. An end tag is always the start tag's name preceded by a slash.
An HTML document begins with the <html> tag, which declares that the document is
written in HTML. Each document has two parts, a head and a body , defined by <head> and
<body> tags, respectively. The head part contains the document title, including the <title>
tag and other information the browser can use when rendering the document, and the body
part holds the actual contents of the document. The header is optional. For more information,
refer to Supplement V.A, HTML and XHTML Tutorial.
The complete syntax of the <applet> tag is as follows:
tag
<applet> tag
<applet
[ codebase = applet_url]
 
 
Search WWH ::




Custom Search