我有这样一段代码代码不执行
// If we click on an unfolded card
if (card.clicked == false) {
clicksCount++;
clickedCards[clicksCount - 1] = card;
card.showCardImage();
if (clicksCount == 2) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
// Loop through clicked cards and if they don't have the
// same ID fold them
if (clickedCards[0].cardID != clickedCards[1].cardID) {
for (int k = 0; k < clickedCards.length; k++) {
clickedCards[k].setDefaultIcon();
clickedCards[k].clicked = false;
}
failedAttempts.setText("Failed Attempts: "
+ ++failedCount);
}
attemptsCount++;
attempts.setText("Attempts " + attemptsCount);
clicksCount = 0; // reset click counter
}
}
这功能我pexeso游戏。第一张牌显示卡的图像很好,但是当我第二次点击时,它不显示图像。它只是等待,然后折叠第一张牌。
我知道这是因为睡觉的线程,但不知道该怎么办。
我会很高兴任何想法或建议。
什么是'卡'(我的水晶球在问'cardID'是否是一个字符串) – 2014-03-28 19:04:02
你也可能想使用一个调试器并自己弄清楚(或缩小问题) – 2014-03-28 19:04:45
@RC .:调试器,虽然通常很有用,但在这里并没有什么帮助,因为程序的逻辑工作得很好,但是问题的原因,Thread.sleep(...)冻结了Swing事件调度线程(EDT),从而冻结了Swing图形,将是很难与标准调试器隔离的东西。 –