开发者

erasing a shape in java

i am trying to draw circles that appear every second, i was able to do so but how do i make the old shape disappear ?

 public void paint(Graphics g) {
  try {
    while (true) {
        Shape circle = new Ellip开发者_运维技巧se2D.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();
} 

}


Just get the background color and use it to cover the old circle with a background-color circle.


Try calling super.paint(g); first thing in the loop.


The easiest method here is to simply call g.clearRect(WIDTH, HEIGHT); up the top of your paint() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜