日期:2014-05-20  浏览次数:20785 次

怎么用一个监听器来实现对两个按钮的监听?
RT

------解决方案--------------------
分别在这两个按钮上注册监听就行了。

你觉得难点是啥?
------解决方案--------------------
把这同一个监听器分别注册到这两个按钮上就ok啊
------解决方案--------------------
Button a=new Button("a");
Button b=new Button("b");
a.addActionListener(new ActionListerner());
b.addActionListener(new ActionListerner());
class ActionListerner implements ActionListener{

@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals("a")){

}
else if(e.getSource().equals("b")){

}
}
就类似上面的