I've tried Thread.sleep(delay), but then the GUI doesn't update the information (like the current roll on the dice). I conducted an experiment and found that if I use a JOptionPane to make the pause, the GUI updates perfectly.
I want to make the program produce the same results, but without the JOptionPane being present.
Any ideas?
Oh, I also tried using a Timer, but it produced the same results as the Thread.sleep().
Here's the code for the computer:
Code: Select all
if (comp) {
while (!pass) {
if (computerScore+roundScore>=GOAL) {
status = name+" has won the game!";
update();
end=true;
} else {
if (computerScore+roundScore>=humanScores+TURNOVER) {
status = "The "+name+" has turned over the dice by default.";
update();
JOptionPane.showMessageDialog(null, status);
status = "";
pass=true;
} else {
rollDice();
if (losePoints()) {
computerScore = 0;
roundScore = 0;
pass=true;
} else
if (loseRound()) {
roundScore = 0;
pass=true;
} else
roundScore += points;
//I want to use a Timer here, instead of JOptionPane.
update();
JOptionPane.showMessageDialog(null, name+" has rolled: "+toString());
System.out.println(toString());
}
}
}
}