title: Adding an action listener to JButtons created by a loop
body: <p>I am having trouble finding a way to invoke an action listener that returns the value of the button clicked in the text area at the bottom. </p>
  
  <p>I made the buttons using a for loop and did not expressly give the buttons a name so I do not know how to reference them when trying to incorporate an <code>ActionListener</code>.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  public class buttoner implements ActionListener {
  //JFrame
  JFrame frame = new JFrame("Button Game");
  
  //Make JPanels
  JPanel panelLabel = new JPanel();
  JPanel buttonGrid = new JPanel(new GridLayout(0,10));
  JPanel bottomPanel = new JPanel();
  
  //JLabel
  private JLabel label1 = new JLabel("The Button Game");
  
  public buttoner() {
      //set layout
      frame.setLayout(new BorderLayout());
      frame.add(panelLabel, BorderLayout.NORTH);
      frame.add(buttonGrid, BorderLayout.CENTER);
      frame.add(bottomPanel, BorderLayout.SOUTH);
      //Set stuff
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(500,700);
      frame.setVisible(true);
      //Change label color
      label1.setForeground(Color.RED);
      //add Label
      panelLabel.add(label1);
      //add Buttons
      for (int i = 1; i &lt;= 60; i++) {
          String val = Integer.toString(i);
          buttonGrid.add(new JButton(val));
      }
      //Add JText Area to bottom JPanel
      String num = "value";
      JTextArea jta = new JTextArea(num, 1, 1);
      bottomPanel.add(jta);
      frame.pack();
  }
  
  public static void main(String args[]){
      buttoner gui = new buttoner();
  }
  
  public void actionPerformed(ActionEvent a) {
  
  }
  }
  </code></pre>