Java Reference
In-Depth Information
The statement in Line 5 displays the second dialog box of the sample run and prompts the
user to enter the width of the rectangle. The entered width is assigned as a string to
widthStr . The statement in Line 6 retrieves the width and stores it in the variable
width .
The statement in Line 7 determines the area, and the statement in Line 8 determines the
perimeter of the rectangle. The statement in Line 9 creates the string containing the
desired output and assigns it to outputStr . The statement in Line 10 uses the output
dialog box to display the desired output, which is shown in the third dialog box of the
sample run. Finally, the statement in Line 11 terminates the program.
The program in Example 6-1 uses input and output dialog boxes to accomplish its job.
When you run this program, you see only one dialog box at a time.
However, suppose that you want the program to display all the input and output in one
dialog box, as shown in Figure 6-2.
FIGURE 6-2 GUI to find the area and perimeter of a rectangle
In Java terminology, such a dialog box is called a graphical user interface (GUI), or
simply a user interface. In this GUI, the user enters the length and width in the top two
white boxes. When the user clicks the Calculate button, the program displays the area
and the perimeter in their respective locations. When the user clicks the Exit button, the
program terminates.
Search WWH ::




Custom Search