Java Reference
In-Depth Information
the top of the window. Two prompts then will be displayed, allowing the user to
enter the input values for inches and pounds. The calculated BMI will be dis-
played below the prompts. An advantage of creating this program as a console
application is that a user does not need a GUI-based operating system or a
mouse to enter data or view the resulting output. The console application thus is
ideal for use on a personal digital assistant (PDA). Another advantage of creating
a console application is that a programmer can validate the program logic before
designing and creating a GUI version of the program.
input
prompts
answer will
display here
FIGURE 3-4a
dialog box
Even though a console application will allow you to
edit, backspace, and even cut and paste as you enter data,
many users feel more comfortable entering data into a
text box or text field. Therefore, a second version of the
Body Mass Index Calculator is developed as a console
application that will accept input via dialog boxes.
A dialog box is a small window that displays mes-
sages and can accept user input. Figure 3-4b shows a
storyboard for a dialog box. To accept user input, a dialog box may include a text
box to accept input data, as shown in Figure 3-4b, or it may include option but-
tons, lists, or other items that allow a user to select from several preset choices.
A dialog box has at least one button and may contain an icon. The title bar of a
dialog box displays a caption and has a Close button.
A dialog box may be displayed as a result of a user action, such as clicking a
button, or it may display as a result of logic in the program. When a dialog box is
displayed, it is displayed in front of the application in which it is running. When
the user finishes entering information or clicks an appropriate button in the dia-
log box, the dialog box closes. The program that called the dialog box, however,
does not necessarily close when the dialog box closes.
Dialog boxes that require the user to complete a specific action, such as
entering data, clicking the Cancel button, or choosing yes or no before returning
to the program's interface, are called modal . Modal dialog boxes give the pro-
grammer control over how the user interacts with the program.
The third version of the Body Mass Index Calculator — an applet with a
Web interface — also will accept user input; however, the applet user will type
data into text boxes and then click a Calculate button in the applet window. As
shown in the storyboard in Figure 3-4c on the next page, the applet window dis-
plays the title of the program, two input prompts with associated text boxes for
data entry, and a Calculate button that causes the program to calculate body
mass index and display the results. The company logo will display as a graphic in
the lower portion of the applet window.
title
bar
text
box
buttons
FIGURE 3-4b
 
Search WWH ::




Custom Search