GUI Changes: The AWT Grows Up |
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, if you haven't already done so.
- Download the latest Swing release, if you haven't already done so.
- Run a Swing application.
- Compile and run a Swing application.
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 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.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. TheREADME.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:
- 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 namedrose.jar
.
Note: Don't bother unarchiving theswing.jar
androse.jar
files! The Swing release depends on finding those archives.
- 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 calledclasses.zip
. Don't uncompress that file! The Java interpreter is in thebin
directory of the JDK release.
- Run the application, specifying a classpath that includes the
swing.jar
file, the JDKclasses.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
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
- Choose a directory to work in.
- Save a Java source file in your working directory. Here's one you can use:
ButtonDemo.java
.
- In your working directory, invoke the Java compiler, specifying the classpath as described in step 3 of the previous section.
- In your working directory, invoke the Java interpreter, as described in step 3 of the previous section..
doc/index.html
(under the top directory of the Swing release).
GUI Changes: The AWT Grows Up |