title: How to add action listener that listens to multiple buttons
body: <p>I'm trying to figure out what i am doing wrong with action listeners. I'm following multiple tutorials and yet netbeans and eclipse are giving me errors when im trying to use an action listener. </p>
  
  <p>Below is a simple program that im trying to get a button working in. </p>
  
  <p>What am i doing wrong?</p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  
  
  public class calc extends JFrame implements ActionListener {
  
  
  
      public static void main(String[] args) {
  
          JFrame calcFrame = new JFrame();
  
          calcFrame.setSize(100, 100);
          calcFrame.setVisible(true);
  
          JButton button1 = new JButton("1");
          button1.addActionListener(this);
  
          calcFrame.add(button1);
      }
  
      public void actionPerformed(ActionEvent e) {
          if(e.getSource() == button1)
      }  
  
  }
  </code></pre>
  
  <p>the action listener is never registered because with the <code>if(e.getSource() == button1)</code> it cant see <code>button1</code>, errors saying cannot find symbol. </p>