dimanche 17 décembre 2017

cannot change variable value inside if statement???? java [duplicate]

Im trying to make a do not disturb feature for my notification in the system tray and im 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 im 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;
        }
    }
});

Aucun commentaire:

Enregistrer un commentaire