Previous Page TOC Next Page


— 5 —
Finding and Using Applets

You probably have some ideas now about applets that you might want to include on your Web pages. Applets are being produced by a variety of sources: individuals, institutions, and, of course, businesses. So how do you go about finding applets that you can use on your Web pages without programming them from scratch? A number of Java resources are available already and more are certainly on the way.

The best place to find applets is on the World Wide Web. Several sites are dedicated to Java and Java applets, and a number of individuals and companies offer their applets for others to use. If you are willing to spend some time looking on the Web, you will certainly come up with a wide variety of sources for applets that you can include in your own pages.

Using applets in your own pages can be a very simple process. Many sites will provide a working example of the applet that you can use to get an idea of configuration, and some sites even have step-by-step instructions for using their applets. Many sites also provide the source code for applets, enabling you to tweak applets to your specific needs or customize applets even further than parameters would allow (parameters are discussed more in Chapter 6). Adding applets to your Web pages can seem more intimidating than it is. This chapter shows you step-by-step how to add an LED tickertape applet to your Web pages. By the end of the chapter, you should have a good idea of the process involved in adding an applet to your own pages.

Where Do I Look?

Several major sites on the World Wide Web are designed to provide a wealth of information about Java and Java applets. Visiting these sites can provide you with tutorials, specifications, and sample applets. Among the major sites for finding Java information on the Net are Sun’s Javasoft site, Gamelan, and JARS. Although these sites contain some of the same information, each site also has a unique twist on the Java offerings and is worth a visit on your quest for applets.

Sun

The Sun Microsystems Web site, Javasoft, is the official site for information about Java (see Figure 5.1). The site contains a wealth of information regarding Java, Java development, and future directions for Java. If you are interested in learning about Java, creating a bookmark for this site would be a good idea:

http://www.javasoft.com

Figure 5.1. The Sun Javasoft Web site is the official site for Java material.

In addition to providing news and information about Java in general, the Javasoft site is also the official source for downloading the HotJava browser, the Java Developer's Kit, and all the official Java documentation. You can find the following information at the Javasoft site:

The About Java and What’s New sections include press releases and announcements relevant to Java developments. Check here for the latest developments and for a listing of Java resources.

The Downloading section is your source for downloading the Java Developer's Kit, the HotJava browser, and the source code for the JDK.

The Documentation section of this site is perhaps the most valuable resource. This section provides extensive documentation and tutorials for the Java language, the JDK, and the HotJava browser. This documentation includes the following:

These documents not only represent the official word on Java, but they are invaluable sources for anyone learning or seriously working with Java.

The Applet section provides some great Java applets. The applets are broken up into sections based on the Application Programming Interface(API) they were designed with, either the Alpha API or the 1.0 release. Chapter 10 covers the 1.0 release. The site also includes some great applet examples, which are accompanied by source code. Some of the applet categories include the following:

Applets to Spice Up a Page

Educational Applets

Utilities

Games and Other Diversions

For Programmers Only

The Developer’s Corner contains information specifically for Java Developers including the documentation resources, JDK resources, and information about training sessions available directly from Sun. The Licensing area contains all of the legal fine print regarding Java, and information about licensing Java for companies that might want to include the Java Virtual Machine in products.

As you explore the possibilities of Java, you should consult the documentation on the Javasoft site quite frequently. As your Java knowledge grows, the documentation you find here can answer more advanced questions and keep your knowledge of Java as current as possible.

Gamelan

EarthWeb's Gamelan is one of the most extensive Java sites available on the Web. It was the first non-Sun site to chronicle the course of Java and its influence on the Web:

http://www.gamelan.com

Figure 5.2. Gamelan offers an extensive repository of Java information and sites.

The Gamelan Web site offers a wide range of Java information, including the following:

The What’s New area of Gamelan provides announcements on the latest available Java information. You can specify how new (in days) you want to search for, and the Gamelan site will return all the new resources it has available. The resources aren’t just limited to applets either; they also include press releases, announcements, and other types of Java resources.

Like many Web sites, Gamelan has a simple rating system it uses to provide you with a basic guideline to the quality of the resources it catalogs. The What’s Cool index provides a listing of resources that the Gamelan administrators consider cool, for whatever reason, be it a new faster applet or a new Java innovation. This area is often a good place to check for cutting-edge applets. Keep in mind that this rating is completely subjective, and although many of the applets are cool, some are just plain goofy.

Because Java is so new, Gamelan provides an additional listing for the various types of applets available in the What's Beta category. A number of applets are designed to use the Alpha version of Java’s API, some use the Beta version, and now more use the official 1.0 API. Gamelan indicates what version of Java an applet or resource uses so you will know whether it is uses the most current version of Java available.

The Who’s Who category provides a listing of all the individuals, organizations, and companies that have contributed resources to Gamelan. This index can be a helpful if you have heard about an applet written by a certain person and want find that applet more directly or look at other applets that person may have written.

Gamelan also offers a search engine to search the site for specific resources (Find a Resource), and a form interface that allows you to submit your own applets for inclusion in the Gamelan site (Add a Resource).

In addition to these features, Gamelan also features a hierarchical index to allow you pursue resources based on subject groupings and a Featured Applet area designed to showcase a particularly innovative new applet. Some of the subject categories in the hierarchical index include the following:

Overall, Gamelan is probably the most comprehensive Java site available and is an incredible resource for anyone working with or exploring Java.

JARS

The Java Applet Rating Service (JARS) offers a site based upon rating applets to provide you with a list of not only new applets, but also applets that are high in quality or functionality:

http://www.surinam.net/java/jars/jars.html

Figure 5.3. The Java Applet Rating Service (JARS) provides a listing of applets and ratings.

When an applet is submitted for inclusion on the JARS site, it is rated and then placed into the appropriate category. The applets are reviewed by a panel of independent judges (who are selected for their experience with Java or their knowledge of the field) and then assigned a rating based on the following criteria:

After the applets have been reviewed by the judges, the applets are placed into various categories that can be searched or viewed in a list. The JARS categories include the following:

The New Applets category offers a listing of applets that have recently been submitted for review. Although these applets have not yet been reviewed, this category is still a good resource for seeing what some of the newest applets are and what they have to offer.

The top percentage listings are designed to break down the applets into the top 1 percent, 5 percent, and 25 percent of all applets that have been reviewed. These listings allow you to look at the applets that ranked the highest in the JARS rating system and bypass applets that received lower rankings.

The Top 100 is simply a listing of the 100 best applets found on the JARS site. It can be worth a look if you want to see some examples of high-quality applets.

You can also use the JARS search engine to search for applets by author, type, or name, and you can use the JARS submission form to submit your own applets for review. JARS also features a “Judges' Pick” where individual judges have an opportunity to select their favorite applets.

Keep in mind that the JARS rating system is still a subjective rating system and does not represent any kind of official rating system. It is simply the JARS’ site’s way of categorizing the applets to help you narrow your search. Many applets that might not have received an outstanding rating for one reason or another are still very useful applets. Also, many applets available on the Web have not been submitted to the JARS site to be reviewed. Consequently, JARS shouldn’t be your only stop while searching the Web for new applets.

Search Engines

The Java-oriented sites are undoubtedly the best way to find a large collection of Java resources on the Net, but don’t overlook traditional search engines or Web indexes in your search for Java material. Search engines can give you access to an incredible number of Java sites on the Web, and the results are not just limited to the larger Java sites. Using search engines you can uncover other Java development companies, consulting agencies, and individuals' pages. Table 5.1 tells you how to find some of the best Web search engines and indexes.

Name


Location


Yahoo

http://www.yahoo.com

Lycos

http://www.lycos.com

WebCrawler

http://www.webcrawler.com

Excite

http://www.excite.com

InfoSeek

http://www.infoseek.com

Alta Vista

http://altavista.digital.com

Code or Binaries?

Once you have located applets that you want to use you will need to figure out how to incorporate them into your own Web pages. There are two ways to go about adding an applet to your Web pages. One is to download the Java binary and configure the HTML code to suit your page, and the other way is to download the source code and compile the applet for yourself.

Using Binaries

Compiled Java applications are represented in binary code. A Java binary is an applet in its executable form. Downloading the binary is the simplest way to get an applet to add to your Web pages. Because the binaries for Java applets are cross-platform, one binary fits all. Authors therefore provide only one copy of their applet that everyone can use. When you find an applet you want to use and it has a binary available, then by all means use the binary. Unless you have plans to modify the code yourself for a specific purpose, downloading the binary will save you time and trouble in getting the applet up and running on your Web pages.

Depending on the configuration of your Web server, you can either download the binary to your PC and then transfer it to your Web page directories or download it straight to your Web page directories. Once you have the binary in your Web directory, adding the binary to your page is as simple as editing the HTML for your page.

Chapter 7 contains a detailed explanation of the HTML tags that are used to add Java to your Web pages. The basic tag is the <APPLET> tag, which allows you to specify an applet for any Java-capable browser. One of the best ways to learn about the HTML code for an applet is to use the View Source option in your browser to look at the HTML code for a page that already contains the applet. Because most applet authors include a working demonstration on their Web pages, it can be quite simple to look at their sources and cut and paste the relevant HTML code directly into your pages. From that point, you can begin to change any customizable code to make the applet perform best for your page, such as changing text or images that might be displayed by the applet.

When downloading a binary, be aware of the names and locations of files. Keep in mind that when you download the file, you need to make sure that you keep the same name for the applet as appears in the HTML code. For example, if an applet is referred to as animate.class in the HTML code, the applet must be named animate.class. Also, be aware that some pages might specify a location for the applet in the HTML code using the <CODEBASE> tag. If you are having trouble making an applet work, try modifying the directory listed in the <CODEBASE> tag to accurately reflect the location of the applet.

You also need to be aware of any supplementary files that the applet needs. Many applets that deal with images, animation, or sound require supplementary files that the applet must access in order to run properly. For example, if an animation applet allows you to specify pictures to be flipped in an animation, you need to be sure that the image files are present and in the proper directory in order for the applet to run properly. You will often find this type of configuration information on the page you downloaded the applet from.


Note: Before adding applets to your pages, you should become very familiar with the applet-specific HTML code. This familiarity will help you avoid problems when customizing an applet for your Web page and will help you troubleshoot a malfunctioning applet. Chapter 7 gives a detailed explanation of the HTML code used in relation to Java applets.

To try out a Java applet, follow the process of adding the LED TickerTape applet (see Figure 5.4) to your Web page. The first step is locating the applet. A search on Gamelan for "LED TickerTape" gives you the URL for the LED TickerTape applet:

http://www.conveyor.com/ticker-tape.html

Figure 5.4. The LED TickerTape enables you to add a scrolling message to your pages with the look of an LED sign.

The site shows you the applet in action. The authors have even included a link to download the necessary files right from the Web page. You need the following three files to use this applet on your own Web pages:

You must create a directory called classes in the directory where your home pages are stored. Place the TickerTape applet files within that classes directory. You can download the files one at a time, or you can download a compressed archive of the files as well. The archives are also linked on the LED TickerTape home page:

Once you have the files in the classes directory, you are halfway done. The only thing you have to do now is edit the actual HTML of the page you want the LED TickerTape applet to appear on.

Add the following code to the HTML file of the Web page to which you want to add the TickerTape applet:

<applet codebase="classes" code="TickerTape" width=500 height=59>

<param name=text value="Congrats! You now have a Ticker Tape applet">

<param name=backcolour value="black">

<param name=framecolour value="darkgrey">

<param name=ledcolour value="red">

<param name=ledoffcolour value="darkgray">

<param name=framethick value=3>

<param name=ledsize value=3>

<param name=ledtype value=0>

<param name=ledspacing value=1>

<param name=speed value=100>

</applet>

This code places the TickerTape applet on your page. You should now be able to view your new page using any Java-capable browser and see the TickerTape applet running and displaying some text (see Figure 5.5).

Figure 5.5. The LED TickerTape applet added to a Web page.

That’s it! Now you have an applet on your page. If you are having trouble, you might want to check out the applet’s install guide at http://www.conveyor.com/ticker-tape.html#install. This site has a listing of some common problems and their solutions.

Once you have this applet installed on your home page, you will undoubtedly want to customize it. After all, what good is a ticker tape if you can’t make it say what you want? You can find the full range of customizations at http://www.conveyor.com/ticker-tape.html# using, but read on to get started right away.

If you look at the HTML used to add this applet, you will notice the following line:

<param name=text value="Congrats! You now have a Ticker Tape applet">

This line specifies the text that appears. You can change the value to whatever text you want, and when you reload the applet, your text should appear in place of the sample text. You can also play around with the colors that are available. Each of the <PARAM> tags represents a parameter that you can configure. The applet accepts black, blue, cyan, darkgray, gray, green, lightgray, magenta, orange, pink, red, white, and yellow as color values for any of the color-related parameters. Experiment with some of these settings to customize the applet to your liking. Chapter 6 goes into more detail about adding applets to your home pages, including the details of the HTML code and some design issues.

Using Code

Many sites do not have binaries available, which means that you will have to use the raw Java code to compile your own version of the applet you want to use. Compiling your own version of an applet only offers an advantage if you are familiar with the Java programming language and want to customize an applet for specific uses on your page beyond what the original author intended. For example, many applets that use images already have a parameter to allow you to specify an image filename. But suppose you also wanted to be able to specify an extension, such as JPEG or GIF to denote the file type. If the author had not already provided a parameter to do so, you would need to modify the source code in order to provide such capability.

Modifying an applet's source code can be a very daunting task. If the code is not well-commented, it can sometimes be difficult for even an advanced programmer to understand completely. You should avoid modifying source code if at all possible unless you have an advanced understanding of what the code does and what you need to modify. If you do attempt to modify the code, you might want to keep an original copy of the code. That way, if your modified code does not function as you anticipated, you can always revert to the original version.

Keep in mind that even if a binary is not available, you will not always have to edit source code. If source code is provided, it is most likely provided in its finished form, and all you will need to do to use it is download the code and compile it. Although modifying the code might seem like a daunting task, compiling code that is in a finished form is a pretty straightforward process once you have a basic understanding of the Java Developer's Kit and the javac compiler provided with it. Chapter 7 covers the Java Developer's Kit and explains the basics of compiling your own Java code (or someone else’s). Once code has been compiled into a binary, you can use it in your pages just as you would any other applet and use the HTML code and parameters to customize the applet for your pages.

Copyright Issues

Downloading and using found elements is part of the nature of the World Wide Web. The Web is based on the open exchange of information. However, Java applets are programs that have authors, and those authors do have certain ownership rights when it comes to the use of their applets and the code they have written.

Java applets are protected by copyright law just as any other applications are, and the extent to which you may use an applet depends upon what rights the author is willing to grant you. Certainly, as Java becomes more popular and applets begin to expand their capabilities, companies will begin to sell applets or applet components. As the practice of selling Java components becomes more widespread, licensing issues will most likely be dealt with just as licensing issues for traditional software or other object-oriented components are dealt with in the market. In the meantime, Java applets are generally falling into the shareware and freeware domain.

Shareware and Freeware

Many applet authors are writing applets as learning exercises or to add specific features to their Web pages. Because they are not large companies producing software for profit, they are not out make a specific product to sell. However, some people still might want to recover some of the expense or time that went into creating their applet, and one way to accomplish that is shareware.

Applets that are released as shareware are provided to anyone through the Net on the condition that if you use the applet past an evaluation period, you will send the author a fee. Most authors allow you to try their programs for a grace period (somewhere between a week and a month) to see whether the software performs the functions you want. However, if you continue to use the software after the trial period, you are bound to send in the shareware fee.

Shareware has some benefits over commercial software and some drawbacks. First, because you are dealing with individuals, shareware fees tend to be very reasonable (between 5 and 45 dollars). Some authors have even produced “Postcardware,” with the fee being a postcard saying, “Thanks.” Second, you are usually free to redistribute or modify shareware as long as you credit the original author. Shareware’s major drawback can be the lack of support. Because most shareware authors don’t have support lines or the time to answer all user questions, you are often on your own if you encounter problems.

In addition to shareware, some applets are released as freeware. As the name implies, freeware applets are given away for anyone to use without a registration fee. Many currently available applets are freeware, and all the author requires is that you retain a copyright statement protecting the original author's rights.

All in all, shareware can be a great way to gain access to some well-written, functional programs. Always check any applet you download to make sure that you are aware of the terms of any agreements for using the software. If you use an applet that is shareware, you are on your honor to send in the registration fee. The shareware system works because of people who register software. If people use shareware software without paying the fees, authors will discontinue to release programs as shareware, and everyone suffers. Because the shareware fees are usually quite reasonable, it’s much better to pay them then risk losing such a valuable resource.

Credit where Credit Is Due

Shareware and freeware demonstrate that not everyone is out to make money for the software they have written. However, most people want recognition in return for their time. Most applets are distributed with a copyright statement that includes information about the original author. There is no reason not to keep that information with the applet when you add it to your own page. It will not adversely effect the performance of the applet, and it is a nice way to give credit where credit is due. If someone has gone to the trouble of producing an applet that you think is great and want to use on your page, why not give them the credit for writing such a great tool? You might someday be in the position of writing applets yourself and would appreciate the same treatment.

Summary

This chapter has shown you where to look for applets and has briefly demonstrated how to include an applet on your Web page. You can begin to look for applets that you might want to include on your own home pages, but using Java applets on your home pages requires learning some new HTML and raises new design issues. Chapter 6 takes a look at the HTML used with Java applets and some of the design issues that Java raises. So read on to begin adding your own Java pages to the Web.

Previous Page TOC Next Page