1

我正在尝试绘制每秒出现的圆圈,我能够这样做但是我如何使旧形状消失?

 public void paint(Graphics g) {
  try {
    while (true) {
        Shape circle = new Ellipse2D.Double(500*Math.random(),500*Math.random(), 50.0f, 50.0f);
        Graphics2D ga = (Graphics2D)g;
        ga.draw(circle);
        ga.setPaint(Color.green);
        ga.fill(circle);
        ga.setPaint(Color.red);
        Thread.sleep(1000);

    }
} catch (InterruptedException e) {
    e.printStackTrace();
} 

}

4

3 回答 3

1

只需获取背景颜色并使用它用背景颜色圆圈覆盖旧圆圈。

于 2011-06-03T00:07:25.983 回答
0

尝试super.paint(g);在循环中调用第一件事。

于 2011-06-03T00:09:39.803 回答
0

这里最简单的方法是简单地调用方法g.clearRect(WIDTH, HEIGHT);的顶部paint()

于 2011-06-03T00:55:19.583 回答