开发者

oval leaves the trail

开发者 https://www.devze.com 2023-03-10 23:14 出处:网络
I am trying to make a simple ball animation, that starts from 1 corner and goes to another corner of the panel.I have written a program for that.

I am trying to make a simple ball animation, that starts from 1 corner and goes to another corner of the panel. I have written a program for that.

When I run the program the oval or ball leaves the trail. What I mean to say is that it leaves it's 'color trail' when the program runs. In my program timer fires an event every 100 milliseconds.

The following is the logic responsible for running the code :

v开发者_StackOverflowoid function() {
  // in this there is a action listener timed accordingly to fire event of 
  // doing x++ every 100th miliseconds
}

public void paintComponent(final Graphics g) {
 g.setColor(Color.black);
 g.drawOval(x,y,width,height);
 g.fillOval(x,y,width,height);
}

Screen shot of the output :

oval leaves the trail


Try

public void paintComponent(final Graphics g) {
 super.paintComponent(g);

 g.setColor(Color.black);
 g.drawOval(x,y,width,height);
 g.fillOval(x,y,width,height);
}
0

精彩评论

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