The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Creating a GUI with JFC/Swing
Lesson: Getting Started with Swing

## Running Swing Applets

> 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:

> 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.
> You can find the applet's source code in `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 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.

> 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.
> The applet's source code is in `AppletDemo.java`. It uses the files `images/right.gif`, `images/middle.gif`, and `images/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.

### Step by Step: Running a Swing-Based Applet

> 1. 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.

> 2. 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.

> 3. 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 Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.