At the moment I have created a physics engine which I am using to produce both a game and simulation. For my simulation, I need to use quite a lot of swing, and am having to created the program using an applet rather than straight JFrame etc.

The program itself is a JPanel and I'm merely opening it through a separate class which extends applet, I'm painting by overriding the paintComponent method and calling it through repaint in actionPerformed (using a swing timer obviously). However, the issue is, even after altering freedom of the components contained by the JPanel program to repaint, and after implementing a basic buffer using BufferedImage alone, there is lots of typical applet flashing when the timer delay is low (frame rate is high)! All my painting is being done in paintComponent as well, therefore I'm not using any form of rendering/game loop that seems modern formality in Java animation that doesn't use swing!

I wondered if there is a possible approach I can take to this using both active and passive rendering, and the most important bit, complies with the fact my main program body is a JPanel! I've endlessly struggle to employ BufferStrategies etc, but keep returning to what I thought would mean having to rewrite my program heavily as a JFrame.

1. You shouldn't use getGraphics().drawImage, you should just use the Graphics object given to you as a parameter.2. JPanels are automatically double buffered so you can just draw directly to the Graphics object they give you.3. Could you give us an example (an applet?) where it flashes?

First one flickers badly, second flickers sometimes, and the third one doesn't flicker at all.

Swing automatically double buffers using BufferStrategy so when drawing on a JComponent or any of its subclasses, you shouldn't worry about double buffering. It's when you start drawing on any AWT Component (which is recommended for games since you are skipping Swing's bloat), that's when you should start double buffering.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org