I
Ike
I have recently had to convert a JDialog to a JFrame (this is MessageDialog
dialog in the method below, which is now a JFrame). Initially, when this was
a dialog, once constructed at the line where dialog = new MessageDialog(..),
execution would then wait until the dialog was closed.
However, under a JFrame, this line is executed, and the code runs right on
through, causing trouble of course. I'd like to have execution essentially
"wait," in this method, is it had when dialog was derived from JDialog, and
am querying for your thoughts on how this may be done with as little
rewriting as possible. Thanks, Ike
// Send the specified message.
private void sendMessage(int type, Message message) {
// Display message dialog to get message values.
MessageDialog dialog;
try {
dialog = new
MessageDialog(owner.gguser,owner.frame/*RalphVince.Misc.RalphFunctions.getJF
rameForComponent(this)*/, type, message);
/////////////////////////// THIS IS WHERE EXECUTION USED TO 'WAIT' UNTIL
dialog was closed /////////////////////
if (!dialog.display()) {
// Return if dialog was cancelled.
return;
}
} catch (Exception e) {
showError("Unable to send message.", false);
return;
}
try {
// Create a new message with values from dialog.
Message newMessage = new MimeMessage(session);
newMessage.setFrom(new InternetAddress(dialog.getFrom()));
Address addy = new InternetAddress(dialog.getTo());
newMessage.setRecipient(Message.RecipientType.TO,addy);
newMessage.setSubject(dialog.getSubject());
newMessage.setSentDate(new Date());
newMessage.setText(dialog.getContent());
// Send new message.
Transport.send(newMessage);
} catch (Exception e) {
showError("Unable to send message.", false);
}
}
dialog in the method below, which is now a JFrame). Initially, when this was
a dialog, once constructed at the line where dialog = new MessageDialog(..),
execution would then wait until the dialog was closed.
However, under a JFrame, this line is executed, and the code runs right on
through, causing trouble of course. I'd like to have execution essentially
"wait," in this method, is it had when dialog was derived from JDialog, and
am querying for your thoughts on how this may be done with as little
rewriting as possible. Thanks, Ike
// Send the specified message.
private void sendMessage(int type, Message message) {
// Display message dialog to get message values.
MessageDialog dialog;
try {
dialog = new
MessageDialog(owner.gguser,owner.frame/*RalphVince.Misc.RalphFunctions.getJF
rameForComponent(this)*/, type, message);
/////////////////////////// THIS IS WHERE EXECUTION USED TO 'WAIT' UNTIL
dialog was closed /////////////////////
if (!dialog.display()) {
// Return if dialog was cancelled.
return;
}
} catch (Exception e) {
showError("Unable to send message.", false);
return;
}
try {
// Create a new message with values from dialog.
Message newMessage = new MimeMessage(session);
newMessage.setFrom(new InternetAddress(dialog.getFrom()));
Address addy = new InternetAddress(dialog.getTo());
newMessage.setRecipient(Message.RecipientType.TO,addy);
newMessage.setSubject(dialog.getSubject());
newMessage.setSentDate(new Date());
newMessage.setText(dialog.getContent());
// Send new message.
Transport.send(newMessage);
} catch (Exception e) {
showError("Unable to send message.", false);
}
}