展开全部
java中得出一个按钮点击的次数,可以使用临时变量32313133353236313431303231363533e58685e5aeb931333337616566来保存点击的次数,在监听事件中对变量进行+1操作,实例如下:importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
publicclassTest{
intcount=0;
publicstaticvoidmain(String[]args){
JButtonA=newJButton("A");
JButtonB=newJButton("B");
JButtonC=newJButton("C");
A.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
methodA();
count++;
}
});
B.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
methodB();
}
});
C.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
methodA();
methodB();
}
});
}
publicstaticvoidmethodA(){
//执行A方法
}
publicstaticvoidmethodB(){
//执行B方法
}
}