所以,我有一个Thread更新JFrame的图形,当我让Thread睡觉时我使用睡眠的对象但是当它醒来时它不在同一个位置。它停止之前。我怎么能阻止它?
public class Handler {
LinkedList<GameObject> object = new LinkedList<GameObject>();
public void tick() throws InterruptedException{
for(int i = 0; i < object.size(); i++){
GameObject tempObject = object.get(i);
tempObject.tick();
if (tempObject.x == 100){
Thread.sleep(1000);
}
}
}
public void render(Graphics g){
for (int i = 0; i < object.size(); i++) {
GameObject tempObject = object.get(i);
tempObject.render(g);
}
}