Adding a Java Applet

 < Day Day Up > 



Java is a programming language that is used to create executable applications that can run in a Web page. Unlike JavaScript, which is a client-side scripting language, Java must be compiled — made into a class file — and stored in the same directory or a subdirectory of the page that loads the class. Parameters can be used to pass specific information in the applet if it is designed to accept it.

Inserting an applet works the same as audio, video, or Flash. You have three options:

  • You can choose Insert ® Media ® Applet.

  • You can click the Applet icon from the Media tools found in the insert bar.

  • You can drag the Applet icon from the insert bar to the document.

In all cases, a dialog box to locate the class file opens. After selecting the class file, you can use the Property inspector to size the applet, add a codebase where the appropriate files are located if the user needs them, and/or add parameters by clicking the Parameters button.

 Habitat Alert site   In this section you add a Java applet to the home page of the Habitat Alert site. The StringWalk applet (created by Bryan Harianto — www.geocities.com/bharianto/StringWalk/StringWalk.html) runs a scrolling news ticker that you can customize to include your own messages, complete with targeted links. It contains parameters where you may add as many messages as you like by using the parameter captionn. For example, caption0 may display the message "Visit our new Habitat Alert store..." Other parameters that this applet accepts are urln and targetn, as in url0 and target0, which would be set to www.habitat-alert.org/store/ and _self. The common number (caption0, url0, and target0) let the applet know that these things are associated and the caption text becomes a link when the user mouses over the text. When clicked, the page loads into the current browser window because the link target is _self.

To add a Java applet to the Habitat Alert home page, follow these steps:

  1. Use the Site panel (window) to locate the java_applets folder and open the file  index.htm. This is the Habitat Alert home page.

  2. Place your cursor beside the "Give a gift that shows you care..." text and add a paragraph return.

  3. Choose Insert ® Media ® Applet and navigate to the java_applets folder in the dialog box that opens. Locate  StringWalk.class and select it. Click OK to insert.

    This applet already has the necessary parameters to contain several captions, URLs, and targets. You can modify how fast the text will move on the screen (right to left), set the color of the background, text, links, and more. A complete list of the parameters follows this exercise.

  4. To set the speed of the scrolling text, select the applet, click the Parameters button, and select Delay. Press Tab twice to move to the Value field and add the value 25. A lower number speeds up the scroll effect; whereas a higher number slows it down.

  5. Add a new caption (caption3) by clicking the Add (+) button. Name the parameter caption3. Press Tab twice to reach the Value field, and type Show your support!

  6. Add another parameter named url3 and press Tab twice. Add the value http://www.habitat-alert.org/store/.

  7. Press Tab twice to add another parameter. Name this target3. Press Tab twice for the value and type _self.

  8. Click OK to close the Parameters dialog box, save your file, and preview by pressing F12.

As shown in Figure 41-8, your captions scroll across the page, and moving your cursor over the text displays the underline to let the site visitor know that this is a clickable link.

click to expand
Figure 41-8: The parameter accolor sets the color for the link and makes the text look clickable.

StringWalk Parameters include the following:

  • delay — Sets the speed of the scrolling text. Text scrolls from right to left.

  • fontface — Sets the font family used to display the text.

  • fontstyle — Lets you set plain, bold, or italic text styles.

  • fontsize — Sets the size of the text.

  • bgcolor — Sets the color used behind the text. Uses R, G, and B values.

  • fgcolor — Sets the color used by the text captions.

  • accolor — Sets the color of the link when users move their cursors over a caption.

  • bdcolor — Sets the color of the border around the applet.

  • captionn — Adds the text to scroll across the applet space. Change n to next sequential integer (for example, if caption3 already exists in the parameters, use caption4). The number must be placed directly after the word without spaces.

  • urln — Adds the URL (absolute) to be used when the visitor clicks a caption. Set the number to match that of the caption for this URL.

  • targetn — Adds a target for the called page. _self opens the file in the current document. _blank opens a new browser window for the file. _frame, _parent, and _top work with frame-based sites. The number used (n) should match the caption and URL for the page.



 < Day Day Up > 



Macromedia Studio MX Bible
Macromedia Studio MX Bible
ISBN: 0764525239
EAN: 2147483647
Year: 2003
Pages: 491

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net