为什么JOptionPane.getValue()继续返回uninitializedValue [英] Why does JOptionPane.getValue() continue to return uninitializedValue

查看:61
本文介绍了为什么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.

I basically want to detect when the user click the cancel in JOptionPane and when the user close the JOptionPane

推荐答案

您应该这样做:

    String s = JOptionPane.showInputDialog(null, "Question");
    System.out.println(s);

如果关闭窗格或按取消",则将返回null字符串.

This will return a null string if the pane is closed or Cancel is pressed.

这篇关于为什么JOptionPane.getValue()继续返回uninitializedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆