Java is waiting for the dialog to close

I have a small program in which an element is drawn and discarded when a drop is executed, I open a dialog (extends Jframe) where some text should be entered. The problem is that I want to wait until this dialog box is closed (in fact, the ok button is pressed so that I can read the data from the text field) than to analyze what the user entered, and based on this I will decide , drop rejected or allowed.

public void drop(DropTargetDropEvent e) {
      try{
            //popup

            Popup p = new Popup();
            p.setParmeter("enter a new name: ");
            p.setVisible(true);

            //programm wont wait before the user has pressed ok in the popup 
            System.out.println("value: " + p.getValue());

            repaint();

        } else {
            e.rejectDrop();
        }
}

, . - , JFrame. , p.getValue() , ok. , , - , , , ok, , , . gui, . .

+3
2

, Popup JDialog JFrame JDialog setModal(true), , .

, JOptionPane, . ( JOptionPane API):

yes/no message 'choose one':

JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION);
+5

Java . JFrame. . tutorial , .

0

Source: https://habr.com/ru/post/1716911/


All Articles