ActionListener的问题
如果我创建了以下JButton,只用一个ActionListener监听这10个JButton要用什么方法确定事件源?JButton b1 = new JButton ("+");
JButton b2 = new JButton ("-");
JButton b3 = new JButton ("+");
JButton b4 = new JButton ("-");
JButton b5 = new JButton ("+");
JButton b6 = new JButton ("-");
JButton b7 = new JButton ("+");
JButton b8 = new JButton ("-");
JButton b9 = new JButton ("+");
JButton b10 = new JButton ("-");
private class bListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if (e.getActionCommand() == "+");
if (e.getActionCommand() == "-"); //getActionCommand()方法只能监听2个JButton.
}
}