JOptionPane 处理它是如何关闭的
JOptionPane handling how it is closed
所以我创建了一个如下所示的 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());
}
}
我想处理 window 在另一个 class 中的关闭方式,但在:
CustomDifficultyWindow a = new CustomDifficultyWindow();
System.out.println(a);
变量 "a" 没有显示 Window 是如何退出的。基本上用哪种方法我可以说如果我的 window 是用 OK 按钮退出的?
这是一个例子:
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
所以我创建了一个如下所示的 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());
}
}
我想处理 window 在另一个 class 中的关闭方式,但在:
CustomDifficultyWindow a = new CustomDifficultyWindow();
System.out.println(a);
变量 "a" 没有显示 Window 是如何退出的。基本上用哪种方法我可以说如果我的 window 是用 OK 按钮退出的?
这是一个例子:
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