title: Repaint() doesn't clear the frame
body: <pre><code>public class Graphics2DTest extends JPanel implements ActionListener{
  private Timer time = new Timer(5,(ActionListener) this);
  int x = 0,y = 0;
  public void paintComponent(Graphics g){
  
      Graphics2D gui = (Graphics2D) g;
      Rectangle2D rectangle = new Rectangle2D.Double(x,y,100,150);
      gui.setPaint(Color.GREEN);
      gui.fill(rectangle);
      time.start();
  }
  
  public void actionPerformed(ActionEvent arg0) {
      x++;
      y++;
      repaint();
  }
  }
  </code></pre>
  
  <p>The problem is repaint() is supposed to clear the frame and draw the rectangle in the position, but the previously painted rectangle remains. So, how to do it? Please explain your answers.</p>