Click here for ObjectSpace: Business- to- Business Integration Company
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


Applet Parameters

The second major part of the <APPLET> tag, applet parameters, is where you can really customize an applet. To make an applet look or act as you want it to, you use a special <PARAM> tag that has two of its own attributes: NAME and VALUE. Although not all applets are customizable, those that are allow you to supply information using one or more <PARAM> tags according to the following format:

<PARAM NAME="parameter name" VALUE="parameter value">

For example, an applet might allow you to provide a sound track that will play in the background when the applet is running. To tell the applet the name of the sound file to use and where that file is located, you could supply the following <PARAM> tag:

<PARAM NAME="sndTrack" VALUE="audio/rock/eagles.au">

In this example, the name of the parameter is sndTrack. The value associated with this parameter, audio/rock/eagles.au, is a relative URL leading to a sound file. Some applets might also accept an absolute URL for this parameter:

<PARAM NAME="sndTrack"
VALUE="http://www.infinitevision.net/audio/rock/beatles.au">

Because the author of an applet must write the programming code that allows the applet to deal with parameters, each applet is unique in the parameters it accepts. For example, another applet might also allow you to specify a sound track. However, depending on how it was written, it might not understand URLs at all. In this case, the applet might insist that the sound file reside in the same directory as the applet itself, meaning that you supply only a filename:

<PARAM NAME="music" VALUE="bluesSong.au">

Here, the applet just looks for the sound file named bluesSong.au, expecting to find it in the same directory in which the applet itself resides. Not only that, but the parameter name isn’t sndTrack. Because the programmer decides which features you can customize, as well as the parameter names that correspond to these features, you’ll find various names used for the same thing. Whereas this applet uses music as the parameter name corresponding to the file with a background sound track, others might use the name background, back music, sound_Track, sound, or just about anything else a programmer can think of.

Applets usually play sounds that are stored in the .au format. That’s why each of the sound files specified here has the .au extension.

Good, Solid Values

Different applets might support any number of different parameters. It’s not unusual, for example, to come across applets that support several different parameters, giving you great flexibility when it comes to configuring them. To supply more than one parameter, all you have to do is enter the parameters one after another.

A Marquee applet, for example, allows you to customize the text that scrolls across the screen. You can specify the font, style, and point size the text should appear in. All you have to do is provide a parameter tag for each:

<PARAM NAME="font_face" VALUE="Helvetica">
<PARAM NAME="font_size" VALUE=24>
<PARAM NAME="font_italic" VALUE="yes">
<PARAM NAME="font_bold" VALUE="no">
<PARAM NAME="marquee" VALUE="The text you are reading will scroll across the screen">

You can customize the preceding applet in various ways, although you don’t necessarily have to supply a parameter for each. Many applets supply a default if you don’t bother to supply a parameter yourself. If, for example, you don’t supply any information about the font, Marquee might use TimesRoman by default. Of course, it’s up to the programmer whether an applet provides a default. Some applets force you to supply parameters; others are written to fall back on default values if you leave parameters out.

As the developer of Visual J++ programs, you must decide which parameters are and are not required. You’ll be the one to determine which default parameters will be acceptable for a program’s operation.

Just as with opening <APPLET> tag attributes, any parameter value that contains a space character (or many spaces) must be surrounded by quotation marks. Of course, when parameters require numeric values, you don’t need to use quotation marks at all.

Multiple Values

Some applets don’t stop at just one value being associated with a given parameter name. In many cases, you can supply several values at once. When this is possible, each value must be separated from the others so as not to confuse the applet. Typically, the | character is used to separate the values:

<PARAM NAME="sounds" VALUE="eagles.au|beatles.au|bach.au">

In this case, the applet receives three sound files as one parameter. Not all applets accept multiple parameters, of course, but those that do insist that you separate each with a special character. Although the | character is the most common, it’s up to the developer of the applet to decide which character you must supply. As a result, don’t be surprised to find commas, colons, semicolons, and even spaces used to separate multiple values:

<PARAM NAME="sounds" VALUE="eagles.au,beatles.au,bach.au">
<PARAM NAME="images" VALUE="shark.gif:pig.gif:tiger.gif">
<PARAM NAME="speeds" VALUE="100 355 23 0 535">

Alternate HTML

Following any parameter tags that you might use, but before the closing </APPLET> tag, there is a special area where you can supply what’s known as alternate HTML. Here, you can enter any amount of HTML code you want; such code will be displayed only by non-Java browsers.

Although applets completely ignore alternate HTML, it’s an important part of the <APPLET> tag nonetheless. Alternate HTML gives you an opportunity to create Web pages that are useful to users who view your pages regardless of the browser they happen to use. If you don’t supply alternate HTML for non-Java browsers, you run the risk of alienating these users.

Although a carriage return between the last <PARAM> tag and the alternate HTML isn’t necessary, it makes the code easier to read.

It’s always a good idea to provide alternate HTML code for your applets whenever possible. Of course, there are some things applets do that you can’t mimic with standard HTML (such as playing music). However, whenever it’s possible to provide alternate HTML code that approximates an applet’s visual appearance, you should do it so that users of both non-Java and Java powered browsers will benefit from your site.

The Closing Applet Tag

The fourth and final part of the <APPLET> tag brings the entire tag to a close. To properly form an <APPLET> tag, you must balance the opening tag with a closing </APPLET> tag. When the browser sees </APPLET>, it knows there is no more to the applet.

Although many applets are quite easy to use for users, others are extremely complex. The more parameters the applet expects, the harder it will be for the Web designer to use. The only way users know how to construct an appropriate <APPLET> tag for a given applet is to read the information that came with the applet. Be sure to include good documentation with your applets.


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.