I am trying to make a do not disturb feature for my notification in the system tray and I am trying to make an if statement that goes if variable dnd = false then change the system tray name to "Do Not Disturb - on" and set dnd to true else set dnd = false but under the dnd = true; and dnd = false; it has a red line and says "Local variable dnd defined in an enclosing scope must be final or effectively final" and I am not sure what to do. Please help.
Here my code:
boolean dnd = false;
doNotDisturb.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {  
        if (dnd == false) {
            dnd = true;
            doNotDisturb.setName("Do Not Disturb - on");
        } else {
            dnd = false;
        }
    }
});
 
     
    