简体   繁体   English

如何使用图形对象清除屏幕?

[英]How can I clear the screen using a graphics object?

I need to clear the screen after using a grid of 我需要在使用网格后清除屏幕

g.drawRect(x * 32, y * 32, 32, 32);

But I need to dispose of what was there before that frame. 但是我需要处理该框架之前的内容。 Is there a 'clear' method, or something like that? 是否有一种“清晰”的方法或类似的方法?

If you want to clear everything that was painted by the previous call of paintComponent(), then at the beginning of that method, add this call: 如果要清除上一次paintComponent()调用绘制的所有内容,请在该方法的开头添加以下调用:

super.paintComponent(g);

Otherwise, you could draw a large rectangle over the entire pane, to cover everything up. 否则,您可以在整个窗格上绘制一个大矩形,以覆盖所有内容。

g.dispose();

should work to clear your screen. 应该可以清除屏幕。 You can read more about it here if you wish to: http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#dispose() 如果愿意,可以在这里阅读更多信息: http : //docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#dispose()

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

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