【发布时间】:2015-05-22 21:57:32
【问题描述】:
我已经缩小了我的问题范围:如果我使用扫描仪,JOptionPane 将不会出现。例如,这很好用:
public static void main(String[] args) {
System.out.println("Before the dialog.");
JOptionPane.showMessageDialog(null, "Please.");
System.out.println("After the dialog.");
}
即使这样也可以:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Before the dialog.");
JOptionPane.showMessageDialog(null, "Please.");
System.out.println("After the dialog.");
}
但是,这不起作用:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int hi = butler.nextInt();
System.out.println("Before the dialog.");
JOptionPane.showMessageDialog(null, "Please.");
System.out.println("After the dialog.");
}
在最后一个示例中,程序等待输入,然后显示“在对话框之前”。之后,程序似乎冻结了。
我尝试在创建对话框之前关闭扫描仪,但没有效果。
【问题讨论】:
-
对我来说很好。也许您的实际代码不同。见stackoverflow.com/help/mcve。
-
您使用的是 IDE 吗? JOptionPane 隐藏在 IDE 界面后面是不是因为 IDE 由于输入而有焦点?
标签: java java.util.scanner joptionpane