Using the JFC/Swing Packages |
With a little work, you can run Swing applets in any browser that implements JDK 1.1.2 or a more recent JDK release. Assuming you already know how to write and deliver an applet, the only tricky part is loading the Swing classes into the browser. The quickest way to load the Swing classes is to put them in the browser's class path.The other way to load Swing into your browser is to provide the Swing JAR file over the network, along with your applet's custom classes. You do this by putting the Swing JAR file in the same directory as your applet's class files and by specifying the Swing JAR file as an archive file. [Check that this works -- I can load everything OK, and the UI looks good, but it's unresponsive.] 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
. Theswing.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
- 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.
- 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.
- 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.
Using the JFC/Swing Packages |