Java Reference
In-Depth Information
Saving, Compiling, and Running the Swing
Version
The Java source code for the Swing version of the Body Mass Index Calculator
program must be saved with a new file name and then compiled before it can be
executed and tested. Once the program is running correctly, a copy of the source
code can be printed for documentation.
Saving and Compiling the Swing Version
As you have learned, Java program names must be the same as the class
statement at the beginning of the code. The program thus must be saved by
using the Save As command and indicating the new file name, BodyMassSwing,
before it can be compiled. The following steps save the source code file on the
Data Disk with a new file name and then compile the source code.
To Save and Compile the Source Code
1. With the Data Disk in drive A, click File on the menu bar and then click
Save As.
2. When the Save As dialog box is displayed, type BodyMassSwing in the
File name text box.
3. If necessary, click the Save as type box arrow and then click Java (*.java)
in the list.
4. If necessary, click the Save in box arrow and then click 3 1 2 Floppy (A:) in
the list. Double-click the Chapter03 folder.
5. Click the Save button in the Save As dialog box.
6. Click Tools on the menu bar and then click Compile Java.
The program is saved with a new file name on the Data Disk and then
compiled. If TextPad notifies you of compilation errors, fix the errors in the
BodyMassSwing coding window and then compile the program again.
OTHER WAYS
1. To Save As, press F12
2. To compile, press
CTRL + 1
3. To compile, at
command prompt,
type javac
BodyMassSwing
.java
Running and Testing the Swing Program
When testing different versions of the same program, it is a good idea to use
the same sample data for each test. That way you can compare output results to
ensure that they are consistent for all versions of the program. The steps on the
next page run and test the interactive program BodyMassSwing.
Search WWH ::




Custom Search