Search code examples
javaif-statementjbutton

How can I stop jButton action?


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.

if a value is not equal to 1 , I just want to stop the action of jButton1. I don't want to stop the whole code & rerun action of jButton1. while a is getting 1. How can I do this?


Solution

  • private void JButton1ActionPerformed( java.awt.event.ActionEvent evt )
    {
        if( count == 1 )
           PerformAction()
    
        else return; //line is optional
    }
    

    Simply put all the ActionPerformed code under an if statement and return out (not necessary) to not perform it.