![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |
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.Other options are to use a JDK 1.1-compliant browser that can find the Swing classes, or 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. For information on setting up 1.1-compliant browsers to work with Swing, see Make Your Browser Swing, an article in The Swing Connection.
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 for
HelloSwingApplet.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 theJava 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 files
images/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 theJDK
. 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 this page. If you can see the first applet but not the second (or the second without any images), please send mail to tutorial@java.sun.com describing what you see in the applet area and in the Java Console.
![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |