Java Reference
In-Depth Information
124
if
(
password.isExpiring
())
125
{
126
msg =
"Password use successful; "
+ password.getRemainingUses
()
+
" use(s) remaining."
;
127
title =
"Success"
;
128
optionType = JOptionPane.WARNING_MESSAGE;
129
}
130
else
131
{
132
msg =
"Password use successful"
;
133
title =
"Success"
;
134
optionType = JOptionPane.INFORMATION_MESSAGE;
135
}
136
}
137
else if
(
e.getSource
()
== jbtChangePswd
)
// user clicked Change password
138
{
139
newPswd =
new
String
(
newPswdField.getPassword
())
;
140
password.set
(
newPswd
)
;
141
142
msg =
"Password changed."
;
143
title =
"Success"
;
144
optionType = JOptionPane.INFORMATION_MESSAGE;
145
}
146
else if
(
e.getSource
()
== jbtAddPswd
)
// user clicked Add password
147
{
148
newPswd =
new
String
(
newPswdField.getPassword
())
;
149
password =
new
Password
(
newPswd,5
)
;
// auto expires after 5 additional uses
150
151
if
(
password.getAutoExpires
())
152
msg =
"Success! Password added with "
+password.getRemainingUses
()
+
" remaining uses."
;
153
else
154
msg =
"Success! Password added - not set to expire."
;
155
156
title =
"Success"
;
157
optionType = JOptionPane.INFORMATION_MESSAGE;
158
}
159
else
// can never happen
160
{
161
msg =
"Please choose a valid action."
;
162
title =
"Invalid Action"
;
163
optionType = JOptionPane.WARNING_MESSAGE;
164
}
165
166
JOptionPane.showMessageDialog
(
this
, msg, title, optionType
)
;
167
pswdField.setText
(
""
)
;
168
newPswdField.setText
(
""
)
;
169
pswdField.requestFocus
()
;
170
171
}
// end of try
172
catch
(
NullPointerException
ex
)
173
{
174
JOptionPane.showMessageDialog
(
this
,
"No Password yet created"
,
175
"Invalid password. Try again."
,
176
JOptionPane.ERROR_MESSAGE
)
;
177
}
178
catch
(
Exception
ex
)
179
{
180
JOptionPane.showMessageDialog
(
this
, ex.getMessage
()
,
181
"Invalid password. Try again."
,
182
JOptionPane.ERROR_MESSAGE
)
;
183
}
184
}
185
}
FIGURE 9-43
Search WWH ::
Custom Search