Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Java GUI: wait for a JFrame to return before continuing to do other stuff

Posted on 2005-05-05
3
Medium Priority
?
670 Views
Last Modified: 2008-02-26
Here's my question. It's probably a common one. I'm in MyFrame2 and executing doSomething function. When I create MyFrame1 instance, there's a fame popping up the screen asking for the user's input. I want to get the input for doSomethingB area so I need to wait till MyFrame1 instance is done. Any good approach for this? I just need hints.

---------------------------------------------
class MyFrame1 extends JFrame(){
  MyFrame1(){}
  ...
}

class MyFrame2 extends JFrame(){
  MyFrame1(){}
  public void doSomething(){
    //do something A
    MyFrame1 frame = new MyFrame1();
    //do something B
  }
}

----------------------------------------------
It should've been JDialog or something. It's too late to change it now as the architecture was done by previous programmers. =/

thanks in advance,
kyle
0
Comment
Question by:oracle1998
3 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13936645
Errr...  you could kick off the other frame in a thread and keep checking in your main thread to see if the frame has closed...

But this is a horrible hack...

You want to change the JFrame to a JDialog and set it as modal

That's the only nice solution... :-(

Tim
0
 

Accepted Solution

by:
gbrose85 earned 400 total points
ID: 13941042
To make your frame modal:

  MyFrame1 frame;
  Runnable modalFrame = new Runnable() {
     public void run() {
         frame = new MyFrame1();
     }
  };

  public void doSomething(){
    //do something A
    SwingUtilities.invokeAndWait(modalFrame);
    //do something B
  }
0
 

Author Comment

by:oracle1998
ID: 13946416
Thanks so much. That's pretty sleek. =)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question