Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
This section describes how to run applets that use Swing components. For information on writing Swing applets, see How to Make Applets.You can run Swing applets in any browser that has the appropriate version of Java Plug-in installed. Another option is to use a 1.2-compliant browser. Currently, the only 1.2-compliant browser available is the Applet Viewer utility provided with the Java 2 SDK.
To test whether your browser can run applets, go to
HelloSwingApplet.html
. You should see a box that looks like the following:You can find the applet's source code in
This is a picture of the applet's GUI. To run the applet, click the picture. The applet will appear in a new browser window.HelloSwingApplet.java
, and the HTML code for including the applet by viewing the HTML source forHelloSwingApplet.html
. The bad news is that the HTML code for including the applet is rather convoluted. The good news is that you can generate the HTML code automatically from a simple<APPLET>
tag. See the Java Plug-in documentation for details on downloading a free HTML converter.Here is a more complex applet, which uses multiple class and image files.
The applet's source code is in
This is a picture of the applet's GUI. To run the applet, click the picture. The applet will appear in a new browser window.AppletDemo.java
. It uses the filesimages/right.gif
,images/middle.gif
, andimages/left.gif
as well.
The rest of this section gives step-by-step instructions for running the preceding applets. For information on writing applets, see How to Make Applets.
- Find a 1.1 or 1.2 browser or download Java Plug-in into a supported browser. Make sure you have the latest version of the browser and plug-in. If nothing else, you can always use Applet Viewer (
appletviewer
), which is distributed in the JDK . Java Plug-in supports certain versions of Netscape Navigator and Internet Explorer. See the Java Plug-in documentation for details.
- If you're using a 1.1 browser without Java Plug-in, determine how to load the Swing JAR file into your browser. See Setting the Browser's Class Path for an example of putting the Swing JAR file into the Applet Viewer class path. See Make Your Browser Swing in The Swing Connection for examples of doing the same for Internet Navigator and Netscape Navigator.
- Point the browser at HelloSwingApplet.html and then AppletDemo.html. You should be able to see at least the first applet. The second one might not show up, or might show up without images, due to firewall issues with the way it's packaged.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.