user238098
user238098

Reputation: 1

How to refresh Jframe to create ainimation?

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

Answers (2)

Peter Lang
Peter Lang

Reputation: 55614

Have a look at this previous post.

Upvotes: 1

camickr
camickr

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

Related Questions