Java Reference
In-Depth Information
(a)
(b)
(c)
F IGURE 16.37
(a) The radio buttons are grouped to let you turn only one light on at a time. (b) The program converts
miles to kilometers, and vice versa. (c) The program converts between decimal, hex, and binary numbers.
*16.4
( Create a miles/kilometers converter ) Write a program that converts miles and
kilometers, as shown in Figure 16.37b. If you enter a value in the Mile text field
and press the Enter key, the corresponding kilometer measurement is displayed
in the Kilometer text field. Likewise, if you enter a value in the Kilometer text
field and press the Enter key, the corresponding miles is displayed in the Mile
text field.
*16.5
( Convert numbers ) Write a program that converts between decimal, hex, and binary
numbers, as shown in Figure 16.37c. When you enter a decimal value in the decimal-
value text field and press the Enter key, its corresponding hex and binary numbers are
displayed in the other two text fields. Likewise, you can enter values in the other fields
and convert them accordingly. (Hint: Use the Integer.parseInt(s, radix)
method to parse a string to a decimal and use Integer.toHexString(decimal)
and Integer.toBinaryString(decimal) to obtain a hex number or a binary
number from a decimal.)
*16.6
( Demonstrate TextField properties ) Write a program that sets the horizontal-
alignment and column-size properties of a text field dynamically, as shown in
Figure 16.38a.
VideoNote
Use radio buttons
and text fields
(a)
(b)
F IGURE 16.38
(a) You can set a text field's properties for the horizontal alignment and col-
umn size dynamically. (b) The program displays the time specified in the text fields.
 
Search WWH ::




Custom Search