title: Java creating an array of colors and utilizing them in shapes
body: <p>I am in some need of guidance with an assignment for class. I currently have a pyramid made up of red and blue rectangles and my task is to randomize those colors by creating an array of various colors (9 to be exact). I am having some trouble creating the array as it keeps getting me an error and I was hoping someone could point me in the right direction to get me started. Here is my code: is my current array even correct? I based that array on an example from my textbook but it didn't seem to work. Any assistance would be greatly appreciated. </p>
  
  <pre><code>@SuppressWarnings("serial")
  public class Legos2 extends JFrame {
     private int startX;
     private int startY;
     private int legoWidth;
     private int legoHeight;
     private int baseLength;
     private int arcWidth;
     private int arcHeight;
  
     //Declare and Array of Colors
      Color[] colors;
  
      //Allocate the size of the array
      colors = new Color[4];
  
      //Initialize the values of the array
      colors[0] = new Color(Color.red);
      colors[1] = new Color(Color.blue);
      colors[2] = new Color(Color.yellow);
      colors[3] = new Color(Color.green);
  
     // Constructor
     public Legos2() {
         super("Jimmy's LEGOs");
         startX = 20;
         startY = 300;
         legoWidth = 50;
         legoHeight = 20;
         baseLength = 10;
         arcWidth = 2;
         arcHeight = 2;
     }
  
     // The drawings in the graphics context
     public void paint(Graphics g) 
     {
         // Call the paint method of the JFrame
         super.paint(g);
  
         int currentX = startX;
         int currentY = startY;
  
         //row = 0 is the bottom row
           for (int row = 1; row &lt;= baseLength; row++)
           {  
          currentX = startX;
  
          System.out.println("row = " + row);
  
          for (int col = 0; col &lt;= baseLength - row; col++)
          {
  
              if (col % 2 == 0)
                  g.setColor(Color.red);
              else
                  g.setColor(Color.blue);
  
              System.out.println("col = " + col);
              g.fillRoundRect(currentX, currentY, legoWidth, legoHeight, arcWidth, arcHeight);
              currentX = currentX + legoWidth;
          }
          currentY -= legoHeight;
          startX += legoWidth /2;
      }
  }
     // The main method
     public static void main(String[] args) {
         Legos2 app = new Legos2();
         // Set the size and the visibility
         app.setSize(550, 325);
         app.setVisible(true);
         // Exit on close is clicked
         app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
     }
  }
  </code></pre>