title: Java JFrame drawing pixel size rectangles
body: <p>I'm creating a JFrame and drawing rectangles 1x1 in size that are each a random color from RGB values from a random generator. When I run the code, the frame draws all the rectangles, but after a few seconds, the rectangles in the frame change. </p>
  
  <p>The Rectangle class:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.Rectangle;
  import java.util.Random;
  import javax.swing.*;
  public class RandomRect extends JComponent
  {
     private static final long serialVersionUID = 1L;
     public void paintComponent(Graphics g)
     {  
        Random rand = new Random();
        Graphics2D g2 = (Graphics2D) g;
        for(int y=1; y&lt;601; y++)
        {
           for(int x=1; x&lt;1201; x++)
           {  
              float red = rand.nextFloat();
              float green = rand.nextFloat();
              float blue = rand.nextFloat();
              Color randomColor = new Color(red, green, blue);
              Rectangle box = new Rectangle(x, y, 1, 1);
              g2.setColor(randomColor);
              g2.fill(box);
           }
        }
        System.out.println("Finished draw");
     }
  }
  </code></pre>
  
  <p>"Finished draw" is printing twice.</p>
  
  <p>The RectViewer class:</p>
  
  <pre><code>import java.awt.Color;
  import javax.swing.*;
  public class RectViewer
  { 
     public static void main(String[] args)
     {
        JFrame frame = new JFrame ();
        frame.setSize(1200,600);
        frame.setTitle("Using the Rectangle Class");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBackground(Color.white);
        RandomRect rect = new RandomRect();
        frame.add(rect);
        frame.setVisible(true);
     }
  }
  </code></pre>
  
  <p>I threw in a println to see if its calling the rectangle class twice and it is, but I don't know why! Can anyone help?</p>