title: Nesting for-loop in Order to Create Brick Wall
body: <p>I am new to programming and this is my first time posting to this site. I am currently working on an assignment which will allow a user to input a number between 1 and 20, and then will create a brick wall based upon the number of brick layers the user entered into the JTextField. I was able to create one row, but I don't really understand nesting statements, and all of the examples I've looked at on the web just confuse me more, so I was wondering if someone could possibly help me to better understand nesting for-loops.</p>
  
  <pre><code>//Package List
  import java.awt.*;
  import java.applet.*;
  import javax.swing.*;
  import java.util.*;
  import java.awt.event.*;
  
  public class Wall extends JApplet implements KeyListener {
  
  
  
  //Component declaration
      JLabel directions;
      JTextField input;
      //Variable declaration
      int startX = 50;
      int startY = 650;
      int width = 50;
      int height = 20;
      int spacing = 2;
  
  
      //Method declaration
      public void init() 
      {
          getContentPane().setBackground(new Color (128, 128, 128));//Changes backround of JApplet to black
          //Set JTextField and JLabel
          setLayout (new FlowLayout( ));
          directions = new JLabel("Enter in any number between 1 and 20 and then press Enter on your keyboard.");
          input = new JTextField ( 10 );
          add (directions );
          add (input);
  
          //Key listener
          addKeyListener( this );
          setFocusable( true );   
      }
  
      //Method declaration 
      public void paint(Graphics g) 
      {
          super.paint (g);
  
          for (int col=1; col&lt;= 8; col++)
           {
           // for (int row; row&lt;=20; row++)
              {   g.setColor (Color.RED);
                  g.fillRect (startX, startY, 50, 20);
                  startX =  startX + spacing + width;
              }
  
           }
      }
  
      //Key event methods
      public void keyReleased( KeyEvent ke ){}
      public void keyTyped (KeyEvent ke ) {}
      public void keyPressed ( KeyEvent ke )
      {
          int key = ke.getKeyCode ( );    
          if (key == KeyEvent.VK_ENTER)
          {
          }
  
      }
  </code></pre>