Start of Tutorial > Start of Trail > Start of Lesson | Search |
Here are the steps for compiling and running your first Swing program with JDK 1.2:
- Download the latest JDK 1.2 release, if you haven't already done so.
- Create a program that uses Swing components.
- Compile the program.
- Run the program.
You can download JDK 1.2 for free.
You can use a simple program we provide, calledSwingApplication
. Please download and save this file:SwingApplication.java
. The spelling and capitalization of the file's name must be exactly "SwingApplication.java".
Your next step is to compile the program. Compiling a Swing program with JDK 1.2 is simple, since the Swing packages are part of JDK 1.2. Here is an example:If you can't compilejavac -deprecation SwingApplication.javaSwingApplication.java
, it's probably either because you're using a JDK 1.1 instead of a JDK 1.2 compiler, or because you're using a beta release of JDK 1.2. Once you update to the most recent JDK 1.2 release, you should be able to use the programs in this trail without change. If you must use JDK 1.2 Beta 4, for some reason, here is how to changeSwingApplication.java
to use the old package names:See Swing Package Names for more information about differences in package names.//import javax.swing.*; //comment out this line import com.sun.java.swing.*; //uncomment this line
After you compile the program successfully, you can run it. This section tells you how to run an application. For instructions on running an applet, see Running Swing Applets.Assuming that your program uses a standard look and feel -- such as the Java Look & Feel, Windows Look & Feel, or CDE/Motif Look & Feel -- you can use the JDK 1.2 interpreter to run the program without adding anything to your class path. For example:
If you use a nonstandard look and feel, you must make sure that its package is included in the class path. For example:java SwingApplicationSolaris: java -classpath .:/home/me/lnfdir/newlnf.jar SwingApplication Win32: java -classpath .;C:\java\lnfdir\newlnf.jar SwingApplication
Note: Don't include the JDK 1.2 classes in the class path. The 1.2 interpreter finds them automatically.
Start of Tutorial > Start of Trail > Start of Lesson | Search |