title: How to fill color in grid boxes randomly
body: <p>How can I fill color on the grid boxes randomly?</p>
  
  <p>Rather than orderly as shown in picture here:</p>
  
  <p><a href="http://www.freeimagehosting.net/uploads/4ed76557de.jpg" rel="nofollow noreferrer">Grid http://www.freeimagehosting.net/uploads/4ed76557de.jpg</a></p>
  
  <pre><code>public class grid extends JPanel{
      Label one = new Label();
      Label two = new Label();
      Label three = new Label();
      Label four = new Label();
  
      public static void main(String[] args){
          JFrame jf=new JFrame();
          jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          jf.add(new YAnswers());
          jf.pack();
          jf.setVisible(true);
      }
  
      grid (){
         int rows=10; int cols=10;
         setLayout(new GridLayout(rows,cols));
         add(one); one.setBackground(Color.red);
         add(two); two.setBackground(Color.orange);
         add(three); three.setBackground(Color.green);
         add(four); four.setBackground(Color.black);
         boxes[] bx=new boxes[rows*cols];
  
          for(int i=0;i&lt;rows*cols;i++){
              System.out.println("i"+i);
              bx[i]=new boxes();
              if(i%2&lt;1)
                  bx[i].setColor(1);
              add(bx[i]);
          }
      } //end grid()
  }
  </code></pre>