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


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

Posted on 2005-05-05
Medium Priority
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(){

class MyFrame2 extends JFrame(){
  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,
Question by:oracle1998
LVL 35

Expert Comment

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... :-(


Accepted Solution

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
    //do something B

Author Comment

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

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