title: Canvas: Double Buffering
body: <p>I like to create a little graphics lib with double buffering to avoid flickering.</p>
  
  <p>So I create a double buffer strategy on a <code>Canvas</code>. I assume that I <code>strategy.getDrawGraphics()</code> returns the current back buffer (the buffer for drawing). Than I draw some stuff on the buffer. Now I assume that <code>strategy.show()</code> flips the back buffer with the front buffer, so that the back buffer get shown on screen. But I don't see a black rectangle when I run the following code:</p>
  
  <pre><code>final JFrame frame = new JFrame();
  frame.setSize(800, 600);
  frame.setVisible(true);
  
  final Canvas canvas = new Canvas();
  frame.add(canvas);
  
  // Double Buffering
  canvas.createBufferStrategy(2);
  final BufferStrategy strategy = canvas.getBufferStrategy();
  
  Graphics2D current = (Graphics2D) strategy.getDrawGraphics();
  current.setColor(Color.BLACK);
  current.fillRect(0, 0, 800, 600);
  strategy.show(); // flip back buffer with front buffer?
  current.dispose();
  Toolkit.getDefaultToolkit().sync();
  
  Thread.sleep(1000);
  frame.dispose();
  </code></pre>