title: Array that Holds JButton Objects
body: <p>Ok, so I'm attempting to do an exercise from a book I'm using to learn Java. Here is the code that I have so far:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.GridLayout;
  import java.awt.BorderLayout;
  public class Calculator {
      //Declaration of all calculator's components.
      JPanel windowContent;
      JTextField displayField;
      JButton button0;
      JButton button1;
      JButton button2;
      JButton button3;
      JButton button4;
      JButton button5;
      JButton button6;
      JButton button7;
      JButton button8;
      JButton button9;
      JButton buttonPoint;
      JButton buttonAdd;
      JButton buttonEqual;
      JPanel pl;
  
      //Constructor creates the components in memory and adds the to the frame using combination of Borderlayout.
      Calculator() {
          windowContent= new JPanel();
  
      // Set the layout manager for this panel
          BorderLayout bl = new BorderLayout();
          windowContent.setLayout(bl);
  
      //Create the display field and place it in the North area of the window
          displayField = new JTextField(30);
          windowContent.add("North",displayField);
  
      //Create button field and place it in the North area of the window
          button0=new JButton("0");
          button1=new JButton("1");
          button2=new JButton("2");
          button3=new JButton("3");
          button4=new JButton("4");
          button5=new JButton("5");
          button6=new JButton("6");
          button7=new JButton("7");
          button8=new JButton("8");
          button9=new JButton("9");
          buttonAdd=new JButton("+");
          buttonPoint = new JButton(".");
          buttonEqual=new JButton("=");
  
      //Create the panel with the GridLayout that will contain 12 buttons - 10 numeric ones, and button with the points
      //and the equal sign.
          pl = new JPanel ();
          GridLayout gl =new GridLayout(4,3);
          pl.setLayout(gl);
      //Add window controls to the panel pl.
          pl.add(button1);
          pl.add(button2);
          pl.add(button3);
          pl.add(button4);
          pl.add(button5);
          pl.add(button6);
          pl.add(button7);
          pl.add(button8);
          pl.add(button9);
          pl.add(buttonAdd);
          pl.add(buttonPoint);
          pl.add(buttonEqual);
  
      //Add the panel pl to the center area of the window
          windowContent.add("Center",pl);
      //Create the frame and set its content pane
          JFrame frame = new JFrame("Calculator");
          frame.setContentPane(windowContent);
      //set the size of the window to be big enough to accomodate all controls.
          frame.pack();
      //Finnaly, display the window
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          Calculator calc = new Calculator();
      }
  }
  </code></pre>
  
  <p>Here is the exercise in exact wording:</p>
  
  <blockquote>
    <p>Modify the class Calculator.java to keep all numeric buttons in the 10-element array declared as follows:  </p>
    
    <p><code>Buttons[] numButtons= new Buttons[10];</code>  </p>
    
    <p>Replace 10 lines that start from  </p>
    
    <p><code>button0=new JButton("0");</code>  </p>
    
    <p>with a loop that creates the buttons and store them in this array.</p>
  </blockquote>
  
  <p>Ok, so I tried declaring the array with the <code>Buttons[] numbuttons line</code>, but that just gave me the error:</p>
  
  <blockquote>
    <p>Multiple markers at this line<br>
    -Buttons can not be resolved to a type<br>
    -Buttons can not be resolved to a type  </p>
  </blockquote>
  
  <p>I instead tried this:</p>
  
  <pre><code>JButton[] buttons = new JButton[10]
  </code></pre>
  
  <p>And then added each button to the array like this:</p>
  
  <pre><code>buttons[0] = "button0";
  </code></pre>
  
  <p>Doing this didn't give me an error when I declared the array, but when I wrote the <code>buttons[0]</code> line, I got this error:</p>
  
  <blockquote>
    <p>Syntax error on token "buttons",delete this token</p>
  </blockquote>
  
  <p>So, I need help figuring out how to do this. Also, the book can be found here: <a href="http://myflex.org/books/java4kids/JavaKid811.pdf" rel="noreferrer">http://myflex.org/books/java4kids/JavaKid811.pdf</a> and the practice is on page 73.
  I apologize if I'm listing to much information. It's just because I'm very new to Java and I'm not sure what is necessary. Help is appreciated. Thanks.</p>