简体   繁体   English

如何刷新Jframe创建动画?

[英]How to refresh Jframe to create ainimation?

I have a simple animation program which moves some basic shapes on the Jframe. 我有一个简单的动画程序,可以在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. 换句话说,我需要强制Jframe清理先前的对象。 How to do so? 怎么做?

看一下以前的帖子

Custom painting is done by overriding the paintComponent() method of a JPanel. 通过重写JPanel的paintComponent()方法可以完成自定义绘制。 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. 阅读Swing教程中有关“自定义绘画”的部分,以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM