簡體   English   中英

使用掃描儀時,為什么我的JOptionPane沒有出現?

[英]Why is my JOptionPane not appearing when I use a Scanner?

我已經解決了我的問題:如果使用掃描儀,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.");
}

在最后一個示例中,程序等待輸入,然后顯示“對話框之前”。 之后,該程序似乎凍結了。

我嘗試在創建對話框之前關閉掃描儀,但這沒有任何效果。

Scanner讀取輸入后,它確實會出現。 它只是沒有出現在頂層窗口中。 請參見JOptionPane不會在其他窗口頂部顯示其對話框,以了解如何解決此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM