Check out this tutorial which explains how to use accelerated graphics mode and double buffering to avoid screen flicker. The key concept is to create a BufferStrategy
to manage the double-buffering:
// create the buffering strategy which will allow AWT
// to manage our accelerated graphics
createBufferStrategy(2);
strategy = getBufferStrategy();
Then, during rendering you obtain the Graphics object from the buffer strategy, perform the rendering using Graphics
and then call strategy.show()
.
// Get hold of a graphics context for the accelerated
// surface and blank it out
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,800,600);
g.dispose();
strategy.show();