title: How can I make a for loop of JButtons?
body: <pre><code>public class BoardView extends JFrame
   {
  
  private JButton board [][];
  
  private GameBoard gameboard;
  
  public static JButton cat1 = new JButton();
  public static JButton cat2 = new JButton();
  public static JButton car1 = new JButton();
  public static JButton car2 = new JButton();
  public static JButton dog1 = new JButton();
  public static JButton dog2 = new JButton();
  public static JButton bike1 = new JButton();
  public static JButton bike2 = new JButton();
  
  public BoardView()
  {
      Container buttonLayout;
      /**
       * Exits the program when closed is clicked
       */
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      /**
       * Sets the title for the Game
       */
      this.setTitle("Memory Of Humanity Game");
      /**
       * Sets the size for the JFrame
       */
      this.setSize(800, 600);
      /**
       * Makes the Pane into a Grid Layout so the Buttons 
       * Line up
       */
      buttonLayout = getContentPane();
      buttonLayout.setLayout(new GridLayout(7, 6));
      /**
       * This adds each JButton to the Pane of the Game
       */
      buttonLayout.add(cat1);
      buttonLayout.add(cat2);
      buttonLayout.add(car1);
      buttonLayout.add(car2);
      buttonLayout.add(dog1);
      buttonLayout.add(dog2);
      buttonLayout.add(bike1);
      buttonLayout.add(bike2)
    }
  }
  </code></pre>
  
  <p>So instead of having to add every JButton one by one like this, how would I create a for loop to do this automatically for me? I have seen a couple on the internet however I don't understand how to loop the the .add part of the JButton. Thank you!</p>