Previous | Next | Trail Map | Creating a User Interface | Using the JFC/Swing Packages

Running a Swing Applet

[PENDING: Recommend Java Plug-in.]

With a little work, you can run Swing applets in browsers that conform to JDK 1.1. Assuming you already know how to write and deliver an applet, the only differences are that a Swing applet must inherit from the JApplet(in the API reference documentation) class and that you need to make sure that the browser can find the necessary Swing classes.

Because the Swing classes are large, you usually want them to be permanently installed in the browser's class path. For now, look at the Make Your Browser Swing, an article in The Swing Connection, for instructions.

The other way to load Swing into your browser is to provide the necessary Swing JAR files over the network, along with your applet's custom classes. You do this by putting the Swing JAR files in the same directory as your applet's class files and by specifying the Swing JAR file as an archive file. [PENDING: Check that this works.] Because the Swing JAR file is very large, loading it over the network takes a long time, As a result, the Swing applet will take a long time to start running.

Do you see three buttons just below this paragraph? If so, you're successfully running a Swing-based applet! The applet's source code is in AppletDemo.java. The swing.jar file is not downloaded with this applet.

The rest of this page gives step-by-step instructions for running the preceding applet.

Step by Step: Running a Swing-Based Applet

  1. Find a 1.1 browser. Make sure you have the latest version, since later versions tend to have bug fixes that make Swing work better. Two 1.1 Java browsers are the HotJava browser and the Applet Viewer (appletviewer), which is distributed in the JDK.

  2. Determine how to load the Swing JAR file into the browser. See Setting the Browser's Class Path for an example of putting the Swing JAR file into the Applet Viewer class path.

  3. Point the browser at this page. You might see an applet security exception when Swing checks whether it has access to the AWT event queue; ignore this exception.


Previous | Next | Trail Map | Creating a User Interface | Using the JFC/Swing Packages