Java Reference
In-Depth Information
The following step enters the code that constructs the buttons and sets the
layout managers.
To Construct the Buttons and Set the Layout Managers
1. Enter lines 81 through 95 as shown in Figure 6-14.
The TextPad window displays the statements to construct the buttons and
set the layouts (Figure 6-15).
code to construct
Buttons using array
FIGURE 6-15
setLayout() methods
set BorderLayout for
Frame and GridLayout
for keypad
The last two arguments of the GridLayout() method in line 94 specify that
10 pixels will display between each of the four rows and four columns, making
the buttons look more like a keypad and adding to the look and feel of the
interface.
Adding Components to the Interface
To add components to the interface, the first task is to add the constructed
Buttons to the keypad Panel and then add the ActionListener to each Button.
The Panel and the TextField then will be added to the Frame.
Because the keypad Panel uses a GridLayout, Java adds buttons beginning in
the upper-left corner. Figure 6-16 on the next page displays the code to add the
16 buttons to the panel using the four-row, four-column grid. Line comments
within the code will help you understand how each loop and add method takes
its turn creating buttons in the keypad.
 
Search WWH ::




Custom Search