Chapter 3: Using Java on Your Pages
|index | previous | next|
Here's a way to move an applet from its default position.
Fig. 3.4 Here the applet is aligned on the right-hand side of the window.
Listing 3.4 Here's another way to move an applet around.
Fig. 3.5 The applet now has a 100-pixel-wide border on every side.
Positioning Java applets on the page
The APPLET tag can be positioned on a Web page much like the IMG tag. Listings 3.3 and 3.4 show how an applet can be moved from the default alignment.
To position a Java applet:
1. <APPLET CODEBASE="classes" CODE="HelloWorld.class" WIDTH=200 HEIGHT=50 ALIGN=RIGHT>
In Figure 3.4, the HelloWorld applet is on the right side of the window. This is because the ALIGN attribute of the APPLET tag has been set to RIGHT.
2. <APPLET CODEBASE="classes" CODE="HelloWorld.class" WIDTH=200 HEIGHT=50 HSPACE=100 VSPACE=100>
In Figure 3.5, the HelloWorld applet is surrounded by 100 pixels of white space on all sides, due to the settings of the HSPACE and VSPACE attributes.
Other valid values for ALIGN are LEFT, RIGHT, TOP, TEXTTOP, MIDDLE, ABSMIDDLE, BASELINE, BOTTOM, and ABSBOTTOM, as described in Table 3.1 (below).
HEIGHT, WIDTH, ALIGN, HSPACE, and VSPACE are all attributes that the APPLET tag shares with the IMG tag. To learn more about these attributes, check out HTML 4 for the World Wide Web, by Elizabeth Castro. (Peachpit Press, 1998)