Babu Kalakrishnan wrote:
> Aloys Oberthür wrote:
>
>> 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();
>
>
> If "md" is really a modal dialog, I would expect this thread to stop
> right here, and continue on to the next line only after the dialog has
> been hidden / disposed off. That's how modal dialogs are expected to
> behave.
>
>>
>> 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();
>>
>
> Couldn't understand what your comments meant either.
>
> BK
It is true, that the Thread stops and displays the modal dialog. But
although I first set the flag within the dialogs actionPerformed method
and then set the dialog to not visible I get two results in the calling
Thread depending on when I invove md.isSuccessful().
The comments referred to the actionCommand, I meant that the command
"one" is the one, where successful is set to true in the
actionPerformed() method above.
Aloys
|