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


Getting Started with Swing

To set up and start using your Swing programming environment, just follow these steps: You can even run a Swing applet, if you're willing to put up with a couple of workarounds.

Download the Latest JDK Release

The Swing release requires some bug fixes that first appeared in JDK 1.1.2. You should download the latest version of the JDK.

Download the Latest JFC Early Access Release

You can download the Swing release from the Java Developers Connection. You'll need to register, if you haven't already, and log in.

Run a Swing Application

Before writing your own Swing programs, you should make sure you can run existing ones. You might want to start by running the SwingSet example, which introduces you to all the Swing components. The README.txt file in the top directory of the Swing release tells you how to run the SwingSet demo.

Here's a general explanation of how to run a Swing application:

  1. Make a note of where your copy of the Swing release is installed. You'll need this to be able to find the Swing classes, as well as the Rose look and feel (if you want to use it). You might want to set the environment variable SWINGHOME to the top directory of the Swing release.

    The archive file containing the Swing classes is in the top-level Swing directory in a file named swing.jar. The various Rose files are archived in the same directory in a file named rose.jar.


    Note: Don't bother unarchiving the swing.jar and rose.jar files! The Swing release depends on finding those archives.

  2. Make a note of where your copy of the JDK 1.1.N release (where N >= 2) is installed. You'll need this to be able to find the proper versions of the JDK classes and interpreter. You might want to set the environment variable JDKHOME to the top directory of the JDK 1.1.N release.

    The JDK classes are in the lib directory of the JDK release, in a file called classes.zip. Don't uncompress that file! The Java interpreter is in the bin directory of the JDK release.

  3. Run the application, specifying a classpath that includes the swing.jar file, the JDK classes.zip file, and the directory containing the program's classes. Be sure that the classes and interpreter you use are from the same 1.1.N release of the JDK!

Compile and Run a Swing Application

  1. Choose a directory to work in.

  2. Save a Java source file in your working directory. Here's one you can use: ButtonDemo.java.

  3. In your working directory, invoke the Java compiler, specifying the classpath as described in step 3 of the previous section.

  4. In your working directory, invoke the Java interpreter, as described in step 3 of the previous section..
If you've gotten this far, you're ready to start writing your own Swing programs! You can learn about Swing through the pages in this tutorial and through the documentation in the Swing release. To read the Swing release's documentation, use a Web browser to view the file doc/index.html (under the top directory of the Swing release).


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