正如我在標題中所說的,我的showConfirmDialog從不等待按下「Yes」或「No」按鈕,只要我叫它。JOptionPane.showConfirmDialog不會停止當前線程
本來我遇到了一個bug讓我變得空白JOptionPanes
,所以現在我使用的是invokeLater
方法。我對這個概念不太熟悉,所以我提前道歉。
public int firstGame()
{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
yOrN = JOptionPane.showConfirmDialog(null,
"Are you ready to play?\n", "Play?", JOptionPane.YES_NO_OPTION);
}
});
return yOrN;
// will return 0 if yes and 1 if no.
}
使用invokeLater
之前,它是工作的罰款(除空白JOptionPane
S)。此方法是否運行另一個線程?我的showInputDialog
如何等待輸入,而不是這個?
不明白,它的有關標準,要求將JOptionPane包裝到invokeLater中, – mKorbel