title: Action listener in an array of Jbuttons placed in 5 differnt JPanels
body: <p>I had an assignment to place the letter of the alphabet in 5 panels with the layout that I coded below.  When you select a button it changes the <code>JLabel</code> to read the button that was clicked.
  The first way I did it, I wrote everything out by adding each button separately to each panel and adding all the <code>ActionListeners</code> and text.  It was about 200 line but worked fine.  I thought it would be more concise to put the <code>JButtons</code> into arrays and add the listeners and text at this point.  I was able to get the <code>JFrame</code> to layout, but I have no idea how to use the <code>ActionListener</code>.  Do I have to add a <code>MouseListener</code> to find out what panel was clicked and then determine the button was pressed?</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Component;
  import java.awt.Container;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.*;
  
  public class JFileCabinet1 extends JFrame implements ActionListener {
      String[] lettersPanel1 = { "A", "B", "C", "D", "E", "F" };
      String[] lettersPanel2 = { "G", "H", "I", "J", "K", "L" };
      String[] lettersPanel3 = { "M", "N", "O", "P", "Q", "R" };
      String[] lettersPanel4 = { "S", "T", "U", "V", "W", "X" };
      String[] lettersPanel5 = { "Y", "Z" };
  
      private JPanel jp1 = new JPanel(new GridLayout(1, 6));
      private JPanel jp2 = new JPanel(new GridLayout(1, 6));
      private JPanel jp3 = new JPanel(new GridLayout(1, 6));
      private JPanel jp4 = new JPanel(new GridLayout(1, 6));
      private JPanel jp5 = new JPanel(new GridLayout(1, 6));
  
      private JButton jblank1 = new JButton();
      private JButton jblank2 = new JButton();
      private JButton jblank3 = new JButton();
      private JLabel jl = new JLabel("");
  
      private Container con = getContentPane();
      private GridLayout layout = new GridLayout(5, 1, 5, 5);
  
      public JFileCabinet1() {
  
          super("File cabinet");
  
          con.add(jp1);
          for (int i = 0; i &lt; lettersPanel1.length; i++) {
              JButton button[] = new JButton[lettersPanel1.length];
              button[i] = new JButton(lettersPanel1[i]);
              jp1.add(button[i]);
              button[i].addActionListener(this);
          }
  
          con.add(jp2);
          for (int i = 0; i &lt; lettersPanel2.length; i++) {
              JButton button[] = new JButton[lettersPanel2.length];
              button[i] = new JButton(lettersPanel2[i]);
              jp2.add(button[i]);
              button[i].addActionListener(this);
          }
  
          con.add(jp3);
          for (int i = 0; i &lt; lettersPanel2.length; i++) {
              JButton button[] = new JButton[lettersPanel3.length];
              button[i] = new JButton(lettersPanel3[i]);
              jp3.add(button[i]);
              button[i].addActionListener(this);
          }
          con.add(jp4);
          for (int i = 0; i &lt; lettersPanel4.length; i++) {
              JButton button[] = new JButton[lettersPanel4.length];
              button[i] = new JButton(lettersPanel4[i]);
              jp4.add(button[i]);
              button[i].addActionListener(this);
          }
  
          con.add(jp5);
          for (int i = 0; i &lt; lettersPanel5.length; i++) {
              JButton button[] = new JButton[lettersPanel5.length];
              button[i] = new JButton(lettersPanel2[i]);
              jp5.add(button[i]);
              button[i].addActionListener(this);
          }
  
          jp5.add(jblank1).setVisible(false);
          jp5.add(jblank2).setVisible(false);
          jp5.add(jblank3).setVisible(false);
  
          setSize(500, 500);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setVisible(true);
          setLayout(layout);
      }
  
      public void actionPerformed(ActionEvent e) {
          JButton src = (JButton) e.getSource();
  
      }
  
      public static void main(String[] args) {
          JFileCabinet1 frame = new JFileCabinet1();
          frame.setVisible(true);
  
      }
  }
  </code></pre>