我有一个带有布局和一个按钮的类。我想知道是否有内置的方法或功能可以检测函数中的布尔值是否发生了变化。我可以用一堆其他布尔值来做到这一点,但我正在寻找一种更优雅的方式。我相信这与“观察者”有关,但并不完全确定。
代码的简化版本如下:
Class checker{
boolean test1 = true;
boolean test2 = true;
checker(){
checkNow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//code to manage, and possibly change the value of the booleans test1 and test2.
//is there any built in function in java where i can test to see if the value of the booleans was changed in this actionListener function?
}
}});
}