title: Need help figuring out how the paintComponent function works within javax.Swing
body: <p>I'm creating a tetris program, and made a for loop that tells the program to create a 10x20 block structure, but I'm having trouble with actually painting the structure (I'm new to java).</p>
  
  <p>I tried filling each block with the color of the block, with magenta if it is a border, black if nothing is there. When the time comes I'm going to assign each shape created a random color that will fill 4 spots in the array.</p>
  
  <pre class="lang-java prettyprint-override"><code>public void start() {
              board = new Color[12][24];
              for (int i = 0; i &lt; 12; i++) {
                  for (int j = 0; j &lt; 23; j++) {
                      if (i == 0 || i == 11 || j == 22) {
                          board[i][j] = Color.MAGENTA;
                      } else {
                          board[i][j] = Color.BLACK;
                      }
                  }
              }
              newPiece();
          }
      @Override 
          public void paintComponent(Graphics g)
          {
              super.paintComponent(g);
              // Paint the well
              g.fillRect(0, 0, 26*12, 26*23);
              for (int i = 0; i &lt; 12; i++) {
                  for (int j = 0; j &lt; 23; j++) {
                      g.setColor(board[i][j]);
                      g.fillRect(26*i, 26*j, 25, 25);
                  }
              }
  </code></pre>
  
  <p>I expected for there to be a 10x20 box to show up with magenta background and black boxes but only the top left border is rendered before the code fails.</p>