摇摆-AWT。如何渲染没有前一帧元素的新帧?

Swing - Awt. How do I render a new frame without the elements from the previous frame?

我正在使用 Swing 和 Awt 库制作一个小游戏。

当我渲染一帧时,我通过 paint() 方法从上一帧添加的图像停留在那里,我的角色,绿色方块,是唯一移动的元素。

如何在更新游戏状态和绘制新帧之前"clean"我的JPanel?

When I render a frame the Images I added through the paint() method

自定义绘画是通过重写 JPanelpaintComponent() 方法完成的,然后将面板添加到 JFrame。并且确保调用 super.paintComponent(...) 作为方法的第一条语句。

阅读 Custom Painting 上的 Swing 教程部分,了解更多信息和工作示例以帮助您入门。