title: Java program double buffered but still flickering, half the time
body: <p>I am following the intermediate java tutorial found at </p>
  
  <p><a href="https://www.youtube.com/watch?v=M2GoiOas2u8&amp;list=PL54DB126285ED0420" rel="nofollow">https://www.youtube.com/watch?v=M2GoiOas2u8&amp;list=PL54DB126285ED0420</a> .</p>
  
  <p>But I am having issues with the double buffering flickering.</p>
  
  <p>my relevant code in two of my classes is as follows</p>
  
  <p>GamePanel.Java</p>
  
  <pre><code>private void gameRender()
  {
      if (dbImage == null) // create the buffer
      {
          dbImage = createImage(GWIDTH, GHEIGHT);
      }
      if (dbImage == null)
      {
          System.err.println("dbImage is still null!");
          return;
      }
      else
      {
          dbg = dbImage.getGraphics();
      }
  
      // Clear the screen
      dbg.setColor(Color.WHITE);
      dbg.fillRect(0, 0, GWIDTH, GHEIGHT);
  
      // Draw Game elements
      draw(dbg);
  }
  
  // Draw all game content in this method
  public void draw(Graphics g)
  {
      world.draw(g);
  }
  
  private void paintScreen()
  {
      Graphics g;
      try
      {
          g = this.getGraphics();
          if (dbImage != null &amp;&amp; g != null)
          {
              g.drawImage(dbImage, 0,  0,  null);
          }
          Toolkit.getDefaultToolkit().sync(); //For some OS.
          g.dispose();
      }
      catch(Exception e)
      {
          System.err.println(e);
      }
  }
  </code></pre>
  
  <p>World.Java</p>
  
  <pre><code>    public void draw(Graphics g)
  {
      for (int i = 0; i &lt; arrayNumber; i++)
      {
          g.drawImage(blockImg[i], blocks[i].x, blocks[i].y, null);
      }
  }
  </code></pre>
  
  <p>Where arrayNumber = 1200.
  This program only has flickering issues when the map is moved to the right or down, (meaning that blocks.x and blocks.y increase for each value of i), but not the other way around. I tried drawing from the bottom right up by replacing each [i] with [arrayNumber - i] and modifying the parameters of the for loop. This made the flickering only occur when moving the map up and to the left. </p>
  
  <p>So I know that I should somehow modify this run method in the world class to somehow use double buffering, but was wondering how I would go about doing so since world doesn't extend JPanel?</p>