0
我有一個實現撲克遊戲的jFrame。我有一個線程,以便計算機對手花時間採取行動。我試圖實現它,以便線程在人輪出現時等待。但是,在我甚至把一名人類玩家放入之前,該框架並不會撥打repaint()
。我在Netbeans中使用過調試器來檢查這個問題:它確實到達了框架調用repaint()
的那一行,但由於某種原因它實際上並沒有這樣做。下面的代碼:Repaint()不在線程中調用
public void run() {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < players.size(); j++) {
Card card = deck.draw();
players.get(i).addToHand(card);
output.append("Player " + players.get(i).getName() + " got a " + card + ".\n");
System.out.println("Player " + players.get(i).getName() + " got a " + card + ".\n");
}
}
while (true) {
if (!players.isEmpty() && players.get(0) instanceof HumanPlayer)
humansTurn = true;
if (humansTurn) {
synchronized (this) {
try {
this.wait();
} catch (InterruptedException e) {
}
}
} else if (humanMoveMade) {
playMove(humanMove, players.remove(0));
humanMoveMade = false;
}else {
//unrelated code, then:
debug.update();
repaint();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
}
}
}
基本上它應該去的是else
每當人類玩家不是讓他或她的舉動,並沒有達到那個repaint
,但它從來沒有經歷出於某種原因。該窗口出現,但沒有任何組件。
編輯:我還要提到的是,repaint()
之前debug.update()
方法調用應該更新其他框架的信息,但沒有被顯示在該窗口向上...
我需要儘快有這個準備,所以我真的需要一些幫助。到底是怎麼回事?