user4054919
user4054919

Reputation: 129

Java how to wait for a dialog window

I am working on a Java GUI program right now. (Using Eclipse+Windowbuilder)

I have the following situation:

The subprogram B calls a Dialog Window to ask the user for input and terminates with calling program A. But I do not want program A to be called yet. It should be called after the Dialog Window terminated.

B:
dialogWindow();
<------- here B should wait for dialogWindow to finish
A();
exit();

Is there a way to wait for dialogWindow()? (I do not want to move the A(); command)

Thanks in advance.

EDIT: The dialogWindow is actually just a normal JFrame.

Upvotes: 2

Views: 671

Answers (2)

sol4me
sol4me

Reputation: 15708

You can either use setModal(true) for YourPopUpComponent that should inherit from JDialog or use JOptionPane.showDialog

import javax.swing.JOptionPane;

public class TestDialog {

    public static void main(String[] args) {

    int resp = JOptionPane.showConfirmDialog(null, "A", "B", JOptionPane.YES_NO_OPTION);        
    if (resp == 0)
     System.out.println("call methodA()");
    else
        System.out.println("call foo()");


    }
}

Upvotes: 3

Sporniket
Sporniket

Reputation: 339

GUI programming in Java is event based.

Thus you add an ActionListener to the submit button of your dialog window, this ActionListener will call A() and terminates.

Upvotes: -2

Related Questions