Reputation: 1
I have a simple animation program which moves some basic shapes on the Jframe. However, the program does not really move the shapes, but creates more instead. In other words, I need to force the Jframe to clean up the previous object. How to do so?
Upvotes: 0
Views: 1518
Reputation: 324207
Custom painting is done by overriding the paintComponent() method of a JPanel. The basic code is:
protected void paintComponent(Graphics g)
{
super.paintComponent(g); // this is what clears the screen.
// paint your shapes here
}
Then you add the panel to the frame.
Read the section from the Swing tutorial on "Custom Painting" for more information.
Upvotes: 0