Usually when I want to make animation, I reset all the graphic screen by drawing rectangle:
@Override
public void paintComponent(Graphics g) {
g.setColor(Color.white);
g.fillRect(0,0,1000,1000);
// now im drawing the animation on empty screen
}
After I drawed the Rect I can draw the animation on empty screen so the animation will move instead of spread. Right now I want to draw animation on Transparent JFrame. How can I empty the component from Precedings drawings, and still keep the JFrame transparent?
paintComponent()
(especially not filling a rectangle with WHITE)repaint()
. In thepaintComponent()
, check for that flag or condition and if true, don't paint anything.Here is a small demo of a semi-transparent frame which paints a line everywhere your mouse goes. Whenever you click on the frame, it removes everything.