首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

如何用一个监听器来实现对两个按钮的监听

2012-04-21 
怎么用一个监听器来实现对两个按钮的监听?RT[解决办法]分别在这两个按钮上注册监听就行了。你觉得难点是啥?

怎么用一个监听器来实现对两个按钮的监听?
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")){

}
}
就类似上面的

热点排行
Bad Request.