Oval leaves a mark

I'm trying to make a simple animation of a ball that starts from the 1st corner and goes to another corner of the panel. I wrote a program for this.

When I run the program, the symbol is oval or leaves a mark. I want to say that it leaves a β€œcolor mark” when the program starts. In my timer program, an event is fired every 100 milliseconds.

The following is the logic responsible for running the code:

 void 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); } 

Screenshot:

+4
source share
1 answer

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); } 
+6
source

All Articles