怎样给多个button加同一个ActionListener

来源:百度知道 编辑:UC知道 时间:2024/05/28 23:51:35
button[buttonint].addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
//ok = button[buttonint].getName();
//System.out.println(" "+ok);
buttonlistener();
}
}
);

谁能帮帮我.这是一个button数组加同一个ActionListener, 但是在ActionListener class里面,我怎么能知道是哪个button发生了事件.

ActionListener 的一个功能就是当用户对Jbutton作出任何action(例如: mouseClick,mouseOver,LeftButtonDown, etc):ActionEvent,如果这个action是定义的, 那么它就会做出响应的反应.

buttonint 返回一个integer,既所对应的哪个Jbutton.
你只要code the button array 如何做就可以,the machine is smart enough to handle this action.