Java Paint()可以被中断吗?# Java - 爪哇娇娃
b*i
1 楼
我有一个变量needsUpdated,在paint()中被查询,如果是true,就更新旋转后的icon
。如下
public void paint(Graphics g){
...
if (theIcon.needsUpdated){
theIcon.rotatedIcon = createRotatedImage(this,...);
theIcon.needsUpdated = false;
}
theIcon.rotatedIcon.paintIcon(this, g,...);
...
}
以上是查询,下面是主动的旋转函数,为了加快速度,我不是每次都更新icon,只作了
标志,每次旋转后第一次画的时候才更新。
public void turn(double angle){
theIcon.rotation +=angle;
theIcon.needsUpdated=true;
}
但是,有的时候可以看到,动画停止的时候,屏幕上的icon的方向是不对的。有没有可
能paint()正进行的时候,turn同时被调
。如下
public void paint(Graphics g){
...
if (theIcon.needsUpdated){
theIcon.rotatedIcon = createRotatedImage(this,...);
theIcon.needsUpdated = false;
}
theIcon.rotatedIcon.paintIcon(this, g,...);
...
}
以上是查询,下面是主动的旋转函数,为了加快速度,我不是每次都更新icon,只作了
标志,每次旋转后第一次画的时候才更新。
public void turn(double angle){
theIcon.rotation +=angle;
theIcon.needsUpdated=true;
}
但是,有的时候可以看到,动画停止的时候,屏幕上的icon的方向是不对的。有没有可
能paint()正进行的时候,turn同时被调