Good day!
I want to disable a button once I click it. My code is as follows..
for (char buttonChar = 'a'; buttonChar <= 'z'; buttonChar++) {
String buttonText = String.valueOf(buttonChar);
JButton letterButton = new JButton(buttonText);
letterButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
System.out.println("actionCommand is: " + actionCommand);
letterButton.setEnabled(false); //I disable the button here
}
});
But an error appears: local variable letter Button is accessed from the inner class; needs to be declared final
.. What does it mean? how can i resolve the issue?
Thank you...