title: Double Buffering a JFrame
body: <p>[Warning, I am a beginner, I have little knowledge about JFrame and I am just getting started, but your help would be greatly appreciated!]</p>
  
  <p>So, here is my Problem: I am currently working on something extremely simple, just a red rectangle moving across the screen and I know how beginner-like that must sound. </p>
  
  <p>My current Code: </p>
  
  <pre><code>package movement;
  
  import java.awt.Color;
  import java.awt.Graphics;
  
  import javax.swing.JFrame;
  
  public class Movement extends JFrame {
  
  public static void main(String[] args) {
  
  
      Movement m = new Movement();
  
      m.setSize(1000, 1000);
      m.setTitle("Movement");
      m.setBackground(Color.WHITE);
      m.setVisible(true);
      m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  
  }
  
  public void paint (Graphics g){
      int width = 0;
      int height = 0;
      int x = 100;
      int y = 900;
  
      while(x &lt; 1000 &amp;&amp; y &gt; 0){
      //System.out.println("Success");    
      g.setColor(Color.RED);
      g.fillRect(x+width, y-height, 200, 200);
      //g.fillRect(x+width, y-height, 200, 200);
      try{
          Thread.sleep(10);
      } catch(InterruptedException e){
      }
      g.setColor(Color.WHITE);
      g.fillRect(x+width, y-height, 200, 200);
      //g.fillRect(x+width, y-height, 200, 200);
      width=width+1;
      height=height+1;
  
      }
  
  
  }
  
  }
  </code></pre>
  
  <p>So as you can see it works, but the image stutters and flicks a bit, since there is only a single Buffer. I heard that adding a JPanel would allow me to double buffer and have a way smoother experience, but since I am a real beginner I wouldn't know how to implement it here. I am not sure how a JPanel would help here and in which way to use it. </p>