Previous | Next | Trail Map | To 1.1 -- And Beyond! | GUI Changes: The AWT Grows Up


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. To download the latest version of the JDK, visit this URL:
http://java.sun.com/products/jdk/1.1/

Download the Latest Swing 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. The front page then has a link to the release, which is called "JFC Early Access." Here's the URL for the Java Developers Connection:
http://java.sun.com/jdc/

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.X release (where X >= 2) is installed. You'll need this to be able to find the 1.1.X classes and the 1.1.X interpreter. You might want to set the environment variable JDKHOME to the top directory of the JDK 1.1.X release.

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

  3. Run the application, specifying a classpath that includes the swing.jar file, the 1.1.X classes.zip file, and the directory containing the program's classes. Be sure to use a 1.1.X interpreter!

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 | To 1.1 -- And Beyond! | GUI Changes: The AWT Grows Up