Java Reference
In-Depth Information
At no point in the code is the size of the applet specified, even though it
is a container. The size of an applet is determined by the HTML that
contains the applet. Any attempt to set the size of the applet is overrid-
den by the HTML.
This applet is displayed in a Web page named hello.html using the
<applet> tag. The HTML looks similar to:
■■
<html>
<body>
<h2>Enter your name and click the button.</h2>
<applet code=”HelloWorldApplet”
width=”200”
height=”75”>
</applet>
</body>
</html>
An applet is embedded in an HTML page by using the <applet> tag. There
are several attributes of the <applet> tag, which are discussed in detail in
the upcoming section The <applet> Tag . For now, I need to discuss the
three attributes of the <applet> tag that are required:
code.
The name of the applet class for this applet.
width.
The width in pixels of the applet.
height.
The height in pixels of the applet.
For example, if the name of your applet class is com.wiley.MyApplet, the
following HTML embeds an instance of MyApplet in a Web page:
<applet code=”com.wiley.MyApplet” width=”400” height=”500”>
</applet>
The size of the applet will be 400 pixels wide and 500 pixels high.
Figure 14.1 shows the hello.html file opened in Internet Explorer, displaying
the HelloWorldApplet.
Search WWH ::




Custom Search