Java Reference
In-Depth Information
The use of concatenation causes the output message to be displayed in
one line. If your screen displays a different BMI than what is displayed in
Figure 3-23 on the previous page, double check the formulas entered on
page 160. Fix any errors, save, and recompile the program.
Printing the Source Code
You may want to print a copy of the BodyMass source code for
documentation purposes or for reference, as you modify the program to
create different versions of the program. The following steps print a copy of the
source code.
To Print the Source Code
1. Click the Print button on the Standard toolbar in the TextPad window.
The source code prints on the printer.
2. Retrieve the printout from the printer.
If you want to print a hard copy of the title, input prompts, and output dis-
played in the command prompt window, you can press A LT + PRINT SCREEN when
the window is active, which saves an image of the current screen to the Windows
Clipboard (your keyboard may use a slightly different name for this key). You
then can paste the picture into a picture editing program, such as Paint, or
another program, such as Microsoft Word or Microsoft PowerPoint, and then
print the document.
Using Swing Components
In 1997, Sun Microsystems introduced a new set of GUI components commonly
referred to as Swing components . As a part of the newer Java Foundation
Classes (JFC) that encompass a group of features to help people build graphical
user interfaces, Swing components are implemented with no native code.
Because Swing components are not restricted to the least common denominator
— that is, the features that are present on every platform — they can have more
functionality than Abstract Window Toolkit (AWT) components.
As defined during program design, a second version of the Body Mass Index
Calculator must be developed as a console application that will accept input via
dialog boxes. As you modify the Body Mass Index Calculator program, you will
edit the file name, change the import statement to import classes in the
javax.swing package, change code to display a Swing input dialog box, and
display output with a Swing message dialog box.
Editing the File Name
Before editing the existing program code, it is appropriate to assign a new file
name to the new version of the program code. The new file name not only distin-
guishes it from the previous version but also better reflects the purpose of the
code in the new file. The file thus is given the file name BodyMassSwing.java.
Search WWH ::




Custom Search