开发者

How to refresh Jframe to create ainimation?

开发者 https://www.devze.com 2022-12-14 23:12 出处:网络
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

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?


Have a look at this previous post.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消