?
=?ISO-8859-1?Q?Aloys_Oberth=FCr?=
I have a question on modal dialogs in (non-event-dispatching)Threads. I
do set a flag in the actionPerformed() method of a modal dialog and the
object which displayed the dialog in the first place can question this
flag after "returning" from show(). I would have expected this to be not
timing dependant, but I see it is not which I do not understand
that's the dialog in essence:
class ModalerDialog extends JDialog implements ActionListener {
boolean flagSuccessful = false;
....
public void actionPerformed(ActionEvent aE) {
String cmd = aEvt.getActionCommand();
if(cmd.equals("one")) {
flagSuccessful = true;
this.setVisible(false);
}
else if(cmd.equals("two")) {
flagSuccessful = false;
this.setVisible(false);
}
}
public boolean isSuccessful() {
return flagSuccessful;
}
}
and that is the Thread launched within the actionPerformed()-method of a
menu ActionListener (see // comments)
Thread t = new Thread() {
public void run() {
ModalerDialog md = new ModalerDialog(owner, true);
md.show();
boolean b = md.isSuccessful(); // now on "one" false
try {
Thread.sleep(250);
}
catch (InterruptedException e1) {}
b = = md.isSuccessful(); // and now on "one" true ????
if(md.isSuccessful())
md.dispose();
else {
md.dispose();
owner.showStartupDialog();
}
}
};
t.start();
Who eplain that to me?
Thanks, Aloys
do set a flag in the actionPerformed() method of a modal dialog and the
object which displayed the dialog in the first place can question this
flag after "returning" from show(). I would have expected this to be not
timing dependant, but I see it is not which I do not understand
that's the dialog in essence:
class ModalerDialog extends JDialog implements ActionListener {
boolean flagSuccessful = false;
....
public void actionPerformed(ActionEvent aE) {
String cmd = aEvt.getActionCommand();
if(cmd.equals("one")) {
flagSuccessful = true;
this.setVisible(false);
}
else if(cmd.equals("two")) {
flagSuccessful = false;
this.setVisible(false);
}
}
public boolean isSuccessful() {
return flagSuccessful;
}
}
and that is the Thread launched within the actionPerformed()-method of a
menu ActionListener (see // comments)
Thread t = new Thread() {
public void run() {
ModalerDialog md = new ModalerDialog(owner, true);
md.show();
boolean b = md.isSuccessful(); // now on "one" false
try {
Thread.sleep(250);
}
catch (InterruptedException e1) {}
b = = md.isSuccessful(); // and now on "one" true ????
if(md.isSuccessful())
md.dispose();
else {
md.dispose();
owner.showStartupDialog();
}
}
};
t.start();
Who eplain that to me?
Thanks, Aloys