我正在爲下週六做一個java任務。在Java中做動畫
它很好,但我正在努力與一節。
在這裏我想揭示一個字符串中的一組數字,一次一個。 我試圖用'Thread.sleep(1000)'減慢循環;'
但沒有什麼顯示,直到線程完成
以下是哪裏的問題是發生 圖形類的部分是有什麼我失蹤?
public void paint(Graphics g)
{
setSize(550, 300);
//this draws all the random numbers, revealing the ans to the user
if (revealNum == 0)
{
g.setColor(Color.BLUE);
g.drawString(randomNumber, 20, 20); //draw String ("the String", x, y)
}
//this reveals the numbers 1 by 1 to the user at the start of the game
if (revealNum==1)
{
for (int x = 0; x < limit; x++)
{
g.setColor(Color.BLUE);
g.drawString(""+x, 20, 20); //draw String ("the String", x, y)
try{
Thread.sleep(1000);
}catch(InterruptedException ex){
System.out.print("Error");
}
repaint();
}
//slow down the loop to show the user
}
看看[這裏](http://stackoverflow.com/questions/9270632/java-wait-for -thread-result-without-blocking-ui)問題。 – Linus 2014-10-17 20:00:14