Problems with actionListener
Hi, I'm having som problems with getSource.
I realize that actionPerformed doesn't recognize the JButtons because of the scope, but as far as I can tell, I have done it like the examples I have followed.
package gui;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
publicclass NumericPanelextends JPanelimplements ActionListener{
public NumericPanel(){
setLayout(new GridLayout(4,3));
//Generating Buttons
JButton b1 =new JButton("1");
JButton b2 =new JButton("2");
JButton b3 =new JButton("3");
JButton b4 =new JButton("4");
JButton b5 =new JButton("5");
JButton b6 =new JButton("6");
JButton b7 =new JButton("7");
JButton b8 =new JButton("8");
JButton b9 =new JButton("9");
JButton bClear =new JButton("Clear");
JButton b0 =new JButton("0");
JButton bEnter =new JButton("Enter");
setLayout(new GridLayout(4,3));
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(bClear);
add(b0);
add(bEnter);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
bEnter.addActionListener(this);
bClear.addActionListener(this);
}
publicvoid actionPerformed(ActionEvent e){
Object button = e.getSource();
if(button = b1){// Says it doesn't recognize b1 - how am I supposed to do this?!
}
}
}

