title: making a chessboard with arrays of JPanel
body: <p>I 'm doing a chessboard , my idea is to make an array of JPanels , each box is a JPanel with color, the problem I have , when I make such assignment
  " chessboard [ rows ] [columns ] = b" and compile gives me an exception .</p>
  
  <p>Why the assignment gives me an error ?</p>
  
  <p>How I can fix it?</p>
  
  <p>Is the layout grid , should go in the JFrame or JPanel ?</p>
  
  <p>thanks.</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0</p>
  </blockquote>
  
  <p>First Class</p>
  
  <pre><code>public class ChessBoard extends JPanel {
      private JPanel[][] chessBoardSquares = new JPanel[8][8];
  
      private final JPanel tile;
  
  
      public ChessBoard () {
          tile = new JPanel();
           tile.setLayout(new GridLayout(8, 8));
  
          for (int rows = 0; rows &lt; 8; rows++) {
              for (int columns = 0;columns&lt; 8;columns++) {
                 JPanel b = new JPanel();
  
                   chessBoardSquares  = new JPanel[rows][columns];
  
                  if ((rows+columns +1)%2 == 0){
                      b.setBackground(Color.WHITE);
                 chessBoardSquares[rows][columns] = b;
                  }
  
                 tile.add(   chessBoardSquares [rows][columns]);
              }
  
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>main</p>
  
  <pre><code>public class example {
      public static void main(String[] args) {
  
  
  
  JFrame window = new JFrame();
  
   ChessBoard chessBoard = new  ChessBoard();
  
  
      window.add( chessBoard  );
      window.setVisible(true);
  
  
  
      }
  
  }
  </code></pre>