Java Event Listener to detect a variable change

前端 未结 7 1711
逝去的感伤
逝去的感伤 2021-02-05 14:38

I cannot seem to find an answer anywhere to my question. Is there any event listener which can detect the changing of a boolean or other variable and then act on it. Or is it p

7条回答
  •  孤城傲影
    2021-02-05 15:13

    The boolean you are setting should be allowed to do only through a setter method like:

    public void setFlag(boolean flag){
        //Method code goes here
    }
    

    Now in now set method, you can decide based on what value comes in, what event needs to be fired. I am explaining in simple terms without introducing complex terms so you can understand better, so code snippet would look like:

    public void setFlag(boolean flag){
    
        //if flag is TRUE do something
        //If flag is FALSE then do something 
    
        //And finally do what you needed to do with flag
    }
    

    Ask questions if you need more info

提交回复
热议问题