Ahh! This is normal. Imagine your panel as a blackboard . Every time you want to redraw what you wrote, you need to erase the board first .
In Java, as in Graphics in general, everything goes the same way. In the drawing method, do the following:
Graphics.clearRect(0,0, getWidth(),getHeight());
If you are better at super.paint(Graphics) theme, do super.paint(Graphics) instead of clearRect() .
source share