Java Reference
In-Depth Information
/** Construct the MailClient JComponent with a Properties filename */
public
public
MailClient
(
String propsFileName
)
throws
throws
Exception
{
super
super
();
// Construct and load the Properties for the mail reader and sender.
Properties mailProps
=
new
new
FileProperties
(
propsFileName
);
// Gather some key values
String proto
=
mailProps
.
getProperty
(
RECV_PROTO
);
String user
=
mailProps
.
getProperty
(
RECV_USER
);
String pass
=
mailProps
.
getProperty
(
RECV_PASS
);
String host
=
mailProps
.
getProperty
(
RECV_HOST
);
iif
(
proto
==
null
null
)
throw
throw new
new
IllegalArgumentException
(
RECV_PROTO
+
"==null"
);
// Protocols other than "mbox" need a password.
iif
(!
proto
.
equals
(
"mbox"
) && (
pass
==
null
null
||
pass
.
equals
(
"ASK"
))) {
String np
;
ddo
{
// Make JOptionPane prompt for password in no-echo.
// Create "message" using JPanel, JLabel, & JPasswordField
// Courtesy of Marc Loy.
JPanel p
=
new
new
JPanel
();
p
.
add
(
new
new
JLabel
(
"Password for "
+
proto
+
" user "
+
user
+
" on "
+
host
));
JPasswordField jpf
=
new
new
JPasswordField
(
20
);
p
.
add
(
jpf
);
JOptionPane
.
showMessageDialog
(
null
null
,
p
,
"Password request"
,
JOptionPane
.
QUESTION_MESSAGE
);
np
=
new
new
String
(
jpf
.
getPassword
());
}
while
null
&&
np
.
length
() ==
0
));
mailProps
.
setProperty
(
RECV_PASS
,
np
);
while
(
np
==
null
null
|| (
np
!=
null
}
// Dump them all into System.properties so other code can find.
System
.
getProperties
().
putAll
(
mailProps
);
// Construct the GUI
// System.out.println("Constructing GUI");
setLayout
(
new
new
BorderLayout
());
JTabbedPane tbp
=
new
new
JTabbedPane
();
add
(
BorderLayout
.
CENTER
,
tbp
);
tbp
.
addTab
(
"Reading"
,
mrb
=
new
new
MailReaderBean
());
tbp
.
addTab
(
"Sending"
,
mcb
=
new
new
MailComposeFrame
());