Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Day 3
Making Applets Live On the Web

Today, you’ll learn how to make your Java applets live on a Web site. First, you’ll learn about the HTML file and what you need to do to edit it. Next, you’ll learn what the <APPLET> tag is and how to use it. Another thing you’ll learn is how to get applets uploaded to your Web site.

Today’s lesson is important for anyone writing applets for Web sites. Application developers who’re writing programs that will run on standalone PCs can skip to Day 4’s chapter, “Debugging Java Applets and Applications.”

In this chapter, we’ll cover these topics:

  The <APPLET> tag
  HTML applet attributes
  Class files
  CODEBASE
  Applet parameters
  Uploading to a Web server
  The Web server layout

For Web developers, this chapter contains skills that are essential for migrating Java applets from local development machines to live Web servers.

The <APPLET> Tag

The <APPLET> tag, used to embed Java applets in Web pages, is the mother of all nonstandard tags. Depending on the applet you are embedding, and to what extent you choose to customize that applet for your page, the <APPLET> tag you must construct can be relatively simple or exceptionally complex.

The <APPLET> tag, like other compound tags, is composed of several parts. However, only a few of these parts are required. Whether or not you must provide anything other than the bare minimum depends entirely on the applet you are configuring. Some applets make heavy use of all parts of the <APPLET> tag; others need only the required parts.

The following code gives a simplified look at the four main parts of the <APPLET> tag:

<APPLET attributes>
applet-parameters
alternet-HTML
</APPLET>

Attributes

As with all tags, both standard and nonstandard, the applet tag begins with an opening tag. And like many other tags, the applet tag supports various attributes—information that is used to enhance the way the applet looks or acts when a browser runs it.

Attributes are keywords that tell browsers to do something special when they encounter a tag; in the case of the <APPLET> opening tag, this something is a bit more complex than with other tags. Although many opening tags consist of nothing more than a letter or two (<A>, <I>, <BR>, and so forth) and no attributes whatsoever, the <APPLET> tag is much more involved. Not only must you provide the initial part of the opening tag (<APPLET>), but you also must supply at least three attributes that together tell the browser the name of the applet and how much space the applet will take up when displayed:

<APPLET CODE="MyApplet" HEIGHT=100 WIDTH=200>

In this example, an applet named MyApplet has been specified. The CODE attribute of the opening tag identifies the file containing the applet. The HEIGHT and WIDTH attributes of the opening tag, on the other hand, are used to tell the browser how much space in the page the applet requires. In this case, the applet takes up 100 pixels in height and 200 pixels in width.

Notice that the name of the applet file, MyApplet, is surrounded by quotation marks, but the height and width values aren’t. This is because the name of an applet file might contain spaces (for example, Ticker Tape), whereas numeric values never will (that is, the number one hundred is always represented by 100, not 10 0, 1 00, or even 1 0 0). Surrounding the name of the applet file with quotation marks ensures that the browser knows exactly what to look for, even if spaces are included with the name. For example, if you left off the quotation marks on an applet file named Ticker Tape, the browser would see only the first word. In this case, the browser would attempt to find the applet file named Ticker and would come up empty-handed.


Note:  Case matters! When supplying the name of an applet file, be sure to type the name exactly, matching each letter case for case. For example, if an applet is named MyApplet, you must specify that name exactly in the CODE attribute. If you specify myapplet instead, the browser won’t be able to find the applet!
About the class Extension

Almost all applets are stored in files having a .class extension. This is a result of the compile process, the final step of which involves converting human-readable Java source code into machine-readable bytecode. When converted, the bytecode is stored in a file with the .class extension.

As a result, the MyApplet applet is really stored in a file named MyApplet.class. Although you’re free to include the .class extension when specifying your applets, you don’t have to. Java-aware browsers know to look for a file with that extension. You must, however, provide the extension if it’s anything other than .class. Thus, the following opening applet tag is functionally equivalent to the one shown previously, although slightly more precise when it comes to the applet filename:

                <APPLET CODE="MyApplet.class" HEIGHT=100 WIDTH=200>


Previous Table of Contents Next


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.