简体   繁体   中英

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

I'm making a little game using the Swing and the Awt libs. 这是我的框架。

When I render a frame the Images I added through the paint() method from the previous frame stay there, my character, the green square, is the only mooving element.

How do I "clean" my JPanel before updating the game status and draw a new frame?

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

Custom painting is done by overriding the paintComponent() method of a JPanel and you add the panel to the JFrame. And you make sure you invoke super.paintComponent(...) as the first statement of the method.

Read the section from the Swing tutorial on Custom Painting for more information and working examples to get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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