Appendix B. Internet-Ready Applets

When the Java™ technology was first introduced, much of the surrounding hype focused on applets because they allow programs to be downloaded to a browser and to run on the fly over the Internet. It's important to keep in mind that applets are just another way of delivering a program. Newer ways of delivering programs are continually being invented, one example is Java WebStart. [1]

[1] You can learn more about Java WebStart at: http://java.sun.com/products/javawebstart/

Applets can run in any browser with a Java Virtual Machine. However, the major browsers haven't kept up with the latest releases of the Java 2 Platform. To ensure that most users can run your applets, you have two options:

Although the Java Plug-in can guarantee the use of the appropriate virtual machine, it is a hefty download, about 6MB. The plug-in is recommended for use on internal corporate intranets but not for distributing applets on the Internet. For this reason, this appendix presents the information you need to write applets that use the JDK 1.1 API.

This appendix starts by telling you how applets work. The next section covers sound, applet parameters, the tag, interapplet communication, and browser requests.

The appendix then discusses factors to consider when writing the graphical user interface (GUI) for your applet and security restrictions on applets. The next section describes the characteristics of a high-quality applet and includes a checklist of annoying behaviors to avoid in your applet. If you're interested in running applets that use the Java 2 SDK, read the last section, Swing-Based Applets (page 457), which has information on running and writing applets that use Swing GUI components.

Internet-Ready Applets

Overview of Applets

A Simple Applet

The Life Cycle of an Applet

Methods for Milestones

Methods for Drawing and Event Handling

Methods for Adding UI Components

What Applets Can and Cannot Do

Test Driving an Applet

Summary

AWT Components

AWT Basic Controls

Other Ways of Getting User Input

Creating Custom Components

Labels

Containers

Other AWT Classes

Taking Advantage of the Applet API

Finding and Loading Data Files

Displaying Short Status Strings

Displaying Documents in the Browser

Sending Messages to Other Applets

Playing Sounds

Defining and Using Applet Parameters

Using theTag

Practical Considerations of Writing Applets

Security Restrictions

Creating a User Interface

Displaying Diagnostics to the Standard Output and Standard Error Streams

Getting System Properties

Threads in AWT Applets

Finishing an Applet

Before You Ship That Applet

The Perfectly Finished Applet

Swing-Based Applets

Running Swing-Based Applets

Writing Swing-Based Applets

Providing an OBJECT/EMBED Tag for Java Plug-in

Converting AWT Applets to Swing Applets

For More Information

Code Samples

Overview of Applets

Категории