Java Reference
In-Depth Information
123
if
(
numItems > 0
)
// at least one entry is in list
124
{
125
for
(
int
i=0; i < numItems && !inList; ++i
)
126
{
127
if
(
stock.equals
((
String
)
jcbStockList.getItemAt
(
i
)))
128
inList =
true
;
129
}
130
}
131
132
return
inList;
133
}
134
135
public void
actionPerformed
(
ActionEvent
e
)
136
{
137
if
(
e.getSource
()
== jbtLogout
)
138
{
139
logoutUser
()
;
140
}
141
else
142
if
(
e.getSource
()
== jbtAddStock
)
143
{
144
stockSymbol = jtfStockSymbol.getText
()
;
145
if
(
stockSymbol.equals
(
""
))
146
JOptionPane.showMessageDialog
(
this
,
"Please enter a stock symbol to
add."
)
;
147
else
148
{
149
if
(
!stockInList
(
stockSymbol
))
150
jcbStockList.addItem
(
stockSymbol
)
;
151
}
152
jtfStockSymbol.setText
(
""
)
;
153
jtfStockSymbol.requestFocus
()
;
154
}
155
else
156
if
(
e.getSource
()
== jcbStockList
)
157
{
158
stockSymbol =
(
String
)
jcbStockList.getSelectedItem
()
;
159
if
(
stockSymbol ==
null
)
160
JOptionPane.showMessageDialog
(
this
,
"Please add a stock to the list."
)
161
else
162
jtfStockSymbol.setText
(
stockSymbol
)
;
163
}
164
else
165
{
166
JOptionPane.showMessageDialog
(
this
,
"Please choose a valid action."
)
;
167
}
168
}
169
170
private void
logoutUser
()
171
{
172
this
.setVisible
(
false
)
;
173
dispose
()
;
174
caller.activate
()
;
// call activate method of caller object
175
}
176
177
// Handler for window opened event
178
public void
windowOpened
(
WindowEvent
event
)
179
{
180
jtfStockSymbol.setText
(
""
)
;
181
jtfStockSymbol.requestFocus
()
;
182
}
183
// Handler for window closing event
184
public void
windowClosing
(
WindowEvent
event
)
185
{
186
logoutUser
()
;
187
}
188
// Handler for window closed event
189
public void
windowClosed
(
WindowEvent
event
)
190
{
191
}
192
// Handler for window iconified event
193
public void
windowIconified
(
WindowEvent
event
)
194
{
195
}
FIGURE 10-41
Search WWH ::
Custom Search