Java Reference
In-Depth Information
}
});
jf
.
pack
();
}
}
Further, the
MailComposeBean
program is a JavaBean, so it can be used in GUI builders and
even have its fields set within a JSP. It has a
main
method, which allows it to be used stan-
dalone (primarily for testing).
To let you compose one or more email messages concurrently, messages being composed are
placed in a
JDesktopPane
, Java's implementation of Multiple-Document Interface (MDI).
Example 17-12
shows how to construct a multiwindow email implementation. Each
MailComposeBean
must be wrapped in a
JInternalFrame
, which is what you need to place
components in the
JDesktopPane
. This wrapping is handled inside the
MailReaderFrame
method, one instance of which is created in the
MailClient
constructor. The
MailReader-
Frame
method
newSend()
creates an instance of
MailComposeBean
and shows it in the
JDesktopFrame
, returning a reference to the
MailComposeBean
so that the caller can use
methods such as
addRecipient()
and
send()
. It also creates a Compose button and places
it below the desktop pane so that you can create a new composition window by clicking the
button.
Example 17-12. MailComposeFrame.java
public
public class
class
MailComposeFrame
MailComposeFrame
extends
extends
JPanel
{
JDesktopPane dtPane
;
JButton newButton
;
protected
protected
int
int
nx
,
ny
;
/** To be useful here, a MailComposeBean has to be inside
* its own little JInternalFrame.
*/
public
public
MailComposeBean
newSend
() {
// Make the JInternalFrame wrapper
JInternalFrame jf
=
new
new
JInternalFrame
();
// Bake the actual Bean
MailComposeBean newBean
=
new
new
MailComposeBean
(
this
this
,
"Compose"
,
400
,
250
);
// Arrange them on the diagonal.
jf
.
setLocation
(
nx
+=
10
,
ny
+=
10
);