为什么 JOptionPane.getValue() 继续返回 uninitializedValue
下面是我的代码,
public static void main(String args[]){
JOptionPane pane = new JOptionPane();
pane.showInputDialog(null, "Question");
Object value = value.getValue();
System.out.println(value.toString()); --> this will print out uninitializedValue
}
我基本上想检测用户何时单击 JOptionPane 中的取消以及用户何时关闭 JOptionPane
Below are my code
public static void main(String args[]){
JOptionPane pane = new JOptionPane();
pane.showInputDialog(null, "Question");
Object value = value.getValue();
System.out.println(value.toString()); --> this will print out uninitializedValue
}
I basically want to detect when the user click the cancel in JOptionPane and when the user close the JOptionPane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该这样做:
如果关闭窗格或按下“取消”,这将返回
null
字符串。You should do this:
This will return a
null
string if the pane is closed or Cancel is pressed.showInputDialog
是一个静态方法,它不会修改JOptionPane
。正如dogbane 指出的那样,您应该检查返回值showInputDialog
。如果您在实例上调用静态方法,某些编译器会生成警告,因此请务必检查编译器警告。在你的情况下调用这样的方法:
showInputDialog
is a static method, it does not modify theJOptionPane
. As dogbane points out you should check the return valueshowInputDialog
.Some compilers generate warnings if you call static methods on instances, so always check compiler warnings. In your case call the method like this: