我该如何停止jButton动作?

时间:2015-05-27 15:59:54

标签: java if-statement jbutton

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//codes for initializing & calculating value of a  
if(a==1){
//if this condition is true jButton action will Continue 
//jButton action code ......}
else{
//if this condition is false jButton action will stop.

如果值不等于1,我只想停止jButton1的操作。我不想停止整个代码和重新运行jButton1的动作。当a得到1.我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

private void JButton1ActionPerformed( java.awt.event.ActionEvent evt )
{
    if( count == 1 )
       PerformAction()

    else return; //line is optional
}

简单地将所有ActionPerformed代码放在if语句下并返回(不必要)以不执行它。