title: Having trouble making object move without flickering in Java
body: <p>I have looked into Double Buffering and plan on implementing it eventually but as of right now I can't figure out how to use it or anything like it. I am trying to make pong so I plan on adding three objects total but for now I just want to get one object to work smoothly. I'm fairly new to graphics so I don't know entirely what I'm doing and I'm just trying to learn as I go.   </p>
  
  <p>Here is my code:</p>
  
  <p>Pong:</p>
  
  <pre><code>public static void main(String[]args) {
      JFrame window= new JFrame();
      window.setTitle("Pong Game");
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      window.setPreferredSize(new Dimension(800,500));
      window.pack();
      window.setVisible(true);
      Ball ball= new Ball();
      Paddle player= new Paddle();
      window.getContentPane().add(ball);
      for(;;) {
          ball.move();
          //window.setContentPane(ball);
          window.setContentPane(player);
          player.move();
      }
  }
  </code></pre>
  
  <p>Paddles:</p>
  
  <pre><code>double x, y, ymove;
  boolean cpu;
  
  public Paddle() {
      x=5;
      y=180;
      ymove=.1;
  }
  
  //passing an integer through to make the computer paddle
  public Paddle(int a) {
      cpu= true;
      x=761;
      y=180;
      ymove=.1;
  }
  
  public void paint(Graphics g) {
      g.setColor(Color.blue);
      g.fillRect((int)x, (int)y, 18, 120);
  }
  
  public void move() {
      y+=ymove;
      if(y&gt;=500-160||y&lt;=0) {
          ymove*=-1;
      }
  }
  </code></pre>
  
  <p>Ball:</p>
  
  <pre><code>double x, y, xspeed, yspeed;
  
  public Ball() {
      x=200;
      y=200;
      xspeed=0;
      yspeed=.1;
  }
  
  public void move() {
      x+=xspeed;
      y+=yspeed;
      if(y&gt;=440||y&lt;=0) {
          yspeed*=-1;
      }
  }
  
  public void paint(Graphics g) {
      g.setColor(Color.black);
      g.fillOval((int)x, (int)y, 20, 20);
  }
  </code></pre>