title: Double Buffering dramatically slows performance
body: <p>Edit: I know this code isn't good, I'm just curious as to Why exactly it is SO bad, when it was taken from an ostensibly reputable source: <a href="https://rads.stackoverflow.com/amzn/click/com/0596007302" rel="nofollow noreferrer" rel="nofollow noreferrer">http://www.amazon.com/Killer-Game-Programming-Andrew-Davison/dp/0596007302</a></p>
  
  <p>I've been working on a grid-based game that has thus far used passive animation, that is, everything is redrawn whenever the user presses a button (characters pop forward a square). Once I got the mechanics working well, I went back and introduced an active rendering loop that takes an FPS value and creates an appropriate UPS, skipping frames if needed to maintain the appropriate UPS.</p>
  
  <p>Everything worked well at first, the FPS/UPS would stay stable/close to one another even past values of 100FPS, but when I tried to implement double-buffering the FPS shot down to about 17, while the UPS remained close to my desired setting!</p>
  
  <p>I've done my research, and I have a secondary, perhaps more opinion-y question below, but my main question is <strong>why is this causing such a massive performance hit?</strong></p>
  
  <p>The following two methods are called each animation loop.</p>
  
  <pre><code>public void buildWorld(){
      if (dbImage == null){
            dbImage = createImage(pWidth, pHeight);
            if (dbImage == null) {
                System.out.println("dbImage is null");
                return;
            }
            else{
                dbg = dbImage.getGraphics();
            }
      }
      //When the above statements are commented out, and the following line
      //Is used without the paintScreen method, a very high FPS is achieved.
      //dbg = this.getGraphics();
  
      dbg.setColor(new Color(0, 0, 0));
      dbg.fillRect(0, 0, this.getWidth(), this.getHeight());
      //various other things are drawn...
  }
  private void paintScreen(){ 
      Graphics g;
      try {
        g = this.getGraphics();
        if ((g != null) &amp;&amp; (dbImage != null)){
            g.drawImage(dbImage, 0, 0, null);
        }
        g.dispose();
      }
      catch (Exception e)
      { System.out.println("Graphics context error: " + e);  }
  }
  </code></pre>
  
  <p>Am I missing something obvious here? Why does this cause an 80% or more loss of FPS?</p>
  
  <p>Now onto some secondary questions. I've based my design so far on "Killer Game Programming in Java" an interesting but outdated book. I'm drawing to a JPanel within a JScrollPane, which gives me some nice click'n'drag, RTS like control of the battlefield, but has made it difficult to implement many of the double-buffering solutions I've been reading about. Basically I've decided that I'm going to have to completely overhaul my design to get over this issue, so the questions remain:</p>
  
  <p>Assuming I want the program to be able to run both windowed and fullscreen, which rendering method would offer the highest performance?</p>
  
  <p>a) an AWT canvas + a JFrame</p>
  
  <p>b) an AWT frame</p>
  
  <p>c) directly to a JFrame</p>
  
  <p>d) how I'm doing it is fine, barring some mistake</p>
  
  <p>Also, I see lots of vague talk about never mixing AWT and Swing, but almost every tutorial I see combines the two at some point. Is this really that bad, or only in certain circumstances?</p>