摇摆动画运行极慢
JPanels
CarArrayListcarsModelCar
Point currentPos; // The current position, initialized in another method when knowing route.double speed; // giving the speed any value still causes the same problem but I have 5 atm.RouteType route; // for this example I only consider one simple route
move() :
switch (this.route) {
case EAST:
this.currentPos.x -= speed;
return this.currentPos;...//only above is relevant in this examplemove()
addCarToEast()View
View
@Override
public void run() {
while (true) {
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!cars.isEmpty()) {
cars.get(i).setLocation(
new Point(getModel.getCars().get(i).move()));
if (i == cars.size() - 1) {
i = 0;
} else {
i++;
}
}
}
}ModelArrayListCarViewArrayListJPanelCarJPanels
ArrayList
相关分类