是这样的,我现在要做一个程序,每次计算完路径之后都要repaint()一次,以便显示这次走的格子和路径,总共40个回合,就要显示40次,但是现在我用Thread.sleep(),程序锁死,用timer的话,直接repaint最后一步,之前的显示不出来,我设的延时参数都是500ms.下面是我按完start按钮之后计算的执行的部分……
DPanel.update()是repaint()命令……
我这么写还是不行啊,帮忙看看哪里不对好么?
private class StartAction extends Thread implements ActionListener
{
run r;
ChasingCatStrDog Strd;
public void actionPerformed(ActionEvent event)
{
eat = 0;
count = 0;
ex = 0;
Thread t = new Thread();
t.start();
label1: while(count < turn && eat == 0 && ex == 0)
{
try
{
r = new run(Str, c, d, grid);
Strd = new ChasingCatStrDog(c, d);
System.out.println("turn " + count +" "+ c.catx +" "+ c.caty);
DPanel.update();
t.sleep(speedvalue);
if (c.catx == gate && c.caty == 0)
{
JDialog exDialog = new exitDialog(UIFrame.this);
exDialog.setVisible(true);
ex = 1;
break label1;
}
count++;
for(int i = 0; i < dn; i++)
{
if((c.catx == d[i].dogx) && (c.caty == d[i].dogy))
{
JDialog eDialog = new eatDialog(UIFrame.this);
eDialog.setVisible(true);
eat = 1;
break label1;
}
}
}
catch(InterruptedException e)
{
}
}
} }
}
我按上面那么写还是最后一次才repaint(),之前的都没有显示啊555
DPanel.update()是repaint()命令……
我这么写还是不行啊,帮忙看看哪里不对好么?
private class StartAction extends Thread implements ActionListener
{
run r;
ChasingCatStrDog Strd;
public void actionPerformed(ActionEvent event)
{
eat = 0;
count = 0;
ex = 0;
Thread t = new Thread();
t.start();
label1: while(count < turn && eat == 0 && ex == 0)
{
try
{
r = new run(Str, c, d, grid);
Strd = new ChasingCatStrDog(c, d);
System.out.println("turn " + count +" "+ c.catx +" "+ c.caty);
DPanel.update();
t.sleep(speedvalue);
if (c.catx == gate && c.caty == 0)
{
JDialog exDialog = new exitDialog(UIFrame.this);
exDialog.setVisible(true);
ex = 1;
break label1;
}
count++;
for(int i = 0; i < dn; i++)
{
if((c.catx == d[i].dogx) && (c.caty == d[i].dogy))
{
JDialog eDialog = new eatDialog(UIFrame.this);
eDialog.setVisible(true);
eat = 1;
break label1;
}
}
}
catch(InterruptedException e)
{
}
}
} }
}
我按上面那么写还是最后一次才repaint(),之前的都没有显示啊555
楼主【jeffsyr】截止到2008-08-01 14:10:37的历史汇总数据(不包括此帖):
发帖的总数量:2 发帖的总分数:20 每贴平均分数:10
回帖的总数量:1 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:2 未结的总分数:20
结贴的百分比:0.00 % 结分的百分比:0.00 %
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=jeffsyr