public class circleGame extends JApplet{
private boolean animationDone;
private ArrayList<Circle> circles = new ArrayList<Circle>();
public void init(){
createCircles(10);
new Thread(){
@Override
public void run(){
while(!animationDone){
updateAnimation();
repaint();
delayAnimation();
}
}
}.start();
}
public void createCircles(int amount){
for(int i=0; i<amount; ++i){
circles.add(new Circle());
}
}
public void delayAnimation(){
try {
Thread.sleep(30);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void updateAnimation(){
for(Circle circle: circles){
circle.x+= circle.deltaX/20.0;
circle.y+= circle.deltaY/20.0;
}
}
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
for(Circle circle: circles){
g2d.setColor(circle.color);
int xPosition = (int) (circle.x-circle.radius);
int yPosition = (int) (circle.y-circle.radius);
int diameter = circle.radius*2;
g2d.fillOval(xPosition, yPosition,
diameter, diameter);
}
}
我正在尝试创建给定数量的圆圈并使它们能够像当前代码一样在没有任何拖动或颜色拖尾的情况下进行动画处理。圆圈应该在 JApplet 上流畅地移动而不拖动颜色