Java Reference
In-Depth Information
Adding Components to the JFrame
The last step in creating the BillPayer() constructor method is to add the
previously constructed components to the JFrame. Figure 8-16 displays the add()
methods and explanatory comments. The components are added to their respec-
tive new panels (lines 94 through 117) in order, from left to right and top to
bottom. The new panels then are added to the fieldPanel (lines 120 through 127
and 131), and in turn, the fieldPanel and buttonPanel are added to the interface
(lines 134 and 135).
92
93
//Add fields to rows
94
firstRow.add ( acctNumLabel ) ;
95
firstRow.add ( pmtLabel ) ;
96
97
secondRow.add ( acctNum ) ;
98
secondRow.add ( pmt ) ;
99
100
thirdRow.add ( firstNameLabel ) ;
101
thirdRow.add ( lastNameLabel ) ;
102
103
104
fourthRow.add ( firstName ) ;
105
fourthRow.add ( lastName ) ;
106
107
fifthRow.add ( addressLabel ) ;
108
109
sixthRow.add ( address ) ;
110
111
seventhRow.add ( cityLabel ) ;
112
seventhRow.add ( stateLabel ) ;
113
seventhRow.add ( zipLabel ) ;
114
115
eighthRow.add ( city ) ;
116
eighthRow.add ( state ) ;
117
eighthRow.add ( zip ) ;
118
119
//Add rows to panel
120
fieldPanel.add ( firstRow ) ;
121
fieldPanel.add ( secondRow ) ;
122
fieldPanel.add ( thirdRow ) ;
123
fieldPanel.add ( fourthRow ) ;
124
fieldPanel.add ( fifthRow ) ;
125
fieldPanel.add ( sixthRow ) ;
126
fieldPanel.add ( seventhRow ) ;
127
fieldPanel.add ( eighthRow ) ;
128
129
130
//Add button to panel
131
buttonPanel.add ( submitButton ) ;
132
133
//Add panels to frame
134
c.add ( fieldPanel, BorderLayout .CENTER ) ;
135
c.add ( buttonPanel, BorderLayout .SOUTH ) ;
136
137
//Add functionality to buttons
138
submitButton.addActionListener ( this ) ;
FIGURE 8-16
Search WWH ::




Custom Search