Alex Rivera | Logout

Java Event Listener to detect a variable change

Asked 2011-11-23T19:24:45.883
18

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 possible to create a custom event listener to detect this?

Please I cannot seem to find a solution to this anywhere and I found this website explaining how to create custom events

Edit
Report

1 Answer

1

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

answered 2011-11-23T19:33:21.433

Your Answer