当重画圆圈时,窗口未被清除;新的圈子会被添加到现有的内容中。
目标是创建三个圆圈,每个颜色一个。
线程调用绘制具有不同半径的圆的移动函数。
public void run() {
try {
while(true){
box.removeAll();
move();
box.removeAll();
sleep(500);
}
} catch (InterruptedException e) {
}
}
public synchronized void move() {
Graphics g = box.getGraphics();
g.setXORMode(box.getBackground());
x1= one.x + ofset;
y1= one.y + ofset;
System.out.println("My Point ("+ x1 + " , " + y1 +")");
g.setColor(Color.green);
g.drawOval(pointA.x-(int)distance1, pointA.y-(int)distance1, (int)distance1*2, (int)distance1*2);
g.setColor(Color.blue);
g.drawOval(pointB.x-(int)distance2, pointB.y-(int)distance2, (int)distance2*2, (int)distance2*2);
g.setColor(Color.red);
g.drawOval(pointC.x-(int)distance3, pointC.y-(int)distance3, (int)distance3*2, (int)distance3*2);
g.dispose();
}
什么是“盒子”?你正在使用哪个GUI?你的问题缺乏背景。 – RealSkeptic 2015-04-04 17:03:40