开发者

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?


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜