Java Reference
In-Depth Information
70
// construct components and initialize beginning values
71
lcd = new TextField ( 20 ) ;
72
lcd.setEditable ( false ) ;
73
keypad = new Panel () ;
74
keys = new Button [ 16 ] ;
75
first = true ;
76
op1 = 0.0;
77
clearText = true ;
78
lastOp = 0;
79
calcPattern = new DecimalFormat ( "########.########" ) ;
80
FIGURE 6-12
Line 73 constructs the Panel to hold the array of 16 buttons constructed in
line 74; these buttons are used to represent the calculator keypad and will be
placed in the Center region of the interface. Lines 75 through 78 set initial values
to the variables, first, op1, clearText, and lastOp. Finally, in line 79, the variable,
calcPattern, is assigned to hold a DecimalFormat with numbers up to eight digits
before and eight digits after the decimal point.
The following step enters code to initialize the calculator variables.
To Enter Code to Initialize Calculator Variables
1. Enter lines 70 through 80 as shown in Figure 6-12.
The TextPad window displays the initialization statements for the calculator
variables (Figure 6-13).
code to initialize
variables
FIGURE 6-13
Recall that the DecimalFormat pattern may contain commas. In this case,
however, a comma in the display might not parse correctly if the result were used
for subsequent operations. Therefore, the pattern has only placeholders and a
decimal point. If the entered number has leading or trailing zeroes, the zeroes
will not display in the TextField.
Search WWH ::




Custom Search