每一个button中都添加一个listener如
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
你的按钮1所要执行的功能
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
你的按钮2所要执行的功能
}
});
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
你的按钮1所要执行的功能
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
你的按钮2所要执行的功能
}
});
JButton button1, button2,button3;
那么:
public void ActionPerformed(ActionEvent e)
{
Object obj=e.getSource(); if( obj == button1 ){
//button1
}
else if( obj == button2){
//button2
}
else{
//button3
}
}
Sun公司可是Java语言的发明者,其站点最有权威性。
http://java.sun.com
if (e.getSource() == getJButtonOk()) {
_OnOk();
}
}
明白吗??