I'm trying to make a button that toggles a boolean on/off when it is pressed. I am already using a similar format for toggling other modules on/off, and it works perfectly. However, for some reason unbeknown to me, the boolean I am trying to assign the variable to never toggles at all.
Here is the code that creates the boolean:
boolean rainbow = false;
panels.add(new Panel("Hub", 50, 50, false) {
public void loadElements() {
getElements().add(new ElementBoolean("Rainbow", rainbow));
}
});
And here is the box class, which gets the boolean variable, and is supposed to toggle it on/off.
private String label;
private boolean property;
public ElementBoolean(String label, boolean property) {
super(label);
this.label = label;
this.property = property;
}
@Override
public void mouseClicked(int mX, int mY, int button)
{
switch(button) {
case 0: {
if(!isSelected(mX, mY)) return;
this.property = !this.property;
break;
}
}
}
Again, this format works fine for handling other modules, but for toggling the boolean is never assigns 'property' to the boolean 'rainbow' as it is supposed to. Therefore, the boolean 'property' is toggled correctly, however the variable 'rainbow' stays false. I'm sorry if I am missing something extremely simple, I just cannot understand why this isn't working.
No stack trace because it doesn't generate any errors.