JOptionPane处理它是如何关闭的

时间:2016-07-01 18:05:59

标签: java joptionpane

所以我创建了一个如下所示的JOptionPane:

public class CustomDifficultyWindow {


public CustomDifficultyWindow(){

    JTextField width = new JTextField();
    JTextField height = new JTextField();
    JTextField bombs = new JTextField();

    Object[] message = {"Breite", width, "Höhe", height, "Bomben",    bombs};

    JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    pane.createDialog(null,"Benutzerdefiniert").setVisible(true);

    System.out.println("Breite: " + width.getText() + ", Höhe:" +  height.getText() + ", Bomben:" + bombs.getText());
}
}

我想处理窗口在另一个类中的关闭方式,但是在:

CustomDifficultyWindow a = new CustomDifficultyWindow();
System.out.println(a);

变量“a”不显示窗口是如何退出的。如果我的窗口是用OK按钮退出的话,基本上我可以说哪种方法?

1 个答案:

答案 0 :(得分:0)

以下是一个例子:

int returnVal = JOptionPane.showConfirmDialog(PARENT_WINDOW, "Some message", "Title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (returnVal == JOptionPane.CANCEL_OPTION) {
    // do something if user cancels.
    return;
}

// user pressed confirm(ok)
... handle user input