简体   繁体   中英

Java JFrame & JPanel Differences with Repaint()

I have been playing about with some simple painting of Graphics2D and have some extremely good help from the community here.

I managed to get the flickering resolved from my "bouncy balls" by moving the code away from the main JFrame class and into a JPanel which I then added to the JFrame class, can anyone tell me why this would make such a difference?

When you draw in a JComponent's paintComponent method (such as a JPanel's), you use Swing which uses double-buffering when drawing by default. Drawing directly in a JFrame's paint method will only allow AWT type drawing since the JFrame directly inherits from Frame, a heavy weight container, and since AWT graphics does not use double buffering by default and this will lead to choppy animation.

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