我想畫圈出現每一秒,我能夠這樣做,但我如何使舊形狀消失?在java中刪除一個形狀
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();
}
}
1)爲了更快提供更好的幫助,請發佈[SSCCE](http://pscode.org/sscce.html)2)'paint(Graphics)'不要在這個千禧年編碼AWT。如果在Swing組件中自定義繪畫,則使用'paintComponent(Graphics)'3)'while(true)'不要在繪畫方法中啓動*無限循環*。 4)'Thread.sleep(1000);'不要在paint方法中等待*。 – 2011-06-03 02:32:19