|
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
At a bare minimum, all opening <APPLET> tags must contain the three attributes shown in the preceding examples: CODE, HEIGHT, and WIDTH. These are known as required attributes, as shown in Table 3.1, because you cant include applets in Web pages without them.
In addition to the three required attributes, you can use various optional attributes to control how an applet appears in your pages. You can include these optional attributes, listed in Table 3.2, anywhere within the opening tag. I recommend, however, that you specify optional attributes after the three required ones to increase the readability of your HTML source code (the exception to this rule is CODEBASE, which should come before the CODE attribute if you use it). Its time to show you a complete example for using the <APPLET> tag. The following HTML code shows you what an <APPLET> tag looks like for the MyApplet program: <APPLET CODE="MyApplet" HEIGHT=100 WIDTH=200 ALT="This is a cool applet" HSPACE=10 VSPACE=25>
The browser doesnt care how the tag appears, as long as it begins with < and ends with >. As a result, you can format your opening tag in any way you want. CODEBASEUnder normal circumstances, the browser expects to find the applet file inside the same directory as the Web page itself. In this case, you must ensure that the applet file and Web page in which it is embedded share the same directory. However, keeping the applet and the Web page in the same directory isnt always possible. What if the applet you want to embed in your page resides halfway around the world? In this case, its physically impossible for your Web page and the applet to reside in the same directory. Figure 3.2 shows a picture of a hypothetical server that has three HTML pages. Each of these HTML pages uses two of the three applets that are stored in the Html/Applets directory.
And what if you want a bunch of different pages on your Web site to use the same applet? What a profound waste of time and Web server space it would be to have to upload a copy of the applet into every directory containing a Web page that used it. A better idea would be to have the applet reside in a central location on your server, where all pages can get to it. But how? Fortunately, the optional CODEBASE tag does just that. It allows you to specify a URL that points to the directory containing your applet. When a Java-savvy browser encounters the CODEBASE attribute, it automatically knows to look for the applet in whatever directory that attribute points to. The URL you supply for CODEBASE can point to a directory on your server, or one on any other server on the Web: <APPLET CODEBASE="http://www.infinitevision.net/applets/" CODE="MyApplet" HEIGHT=100 WIDTH=200> In this example, browsers wont look for the MyApplet applet inside the same directory as the Web page containing this <APPLET> tag. Instead, browsers expect the applet to be located on the Infinite Vision Technologies server, inside the applets directory. The CODEBASE tag is particularly helpful when a number of pages on your site use the same applet. Rather than having multiple copies of the same applet scattered all around your server, you can place a single copy of the applet in one directory and specify the appropriate CODEBASE attribute in all pages. Not only does this take the headache out of creating these pages, because you no longer have to upload a copy of the applet for every page that uses it, but it also makes upgrading the applet a cinchsimply upgrade the single applet and youre done. The URL you supply for CODEBASE can be either relative or absolute.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |