ボタンをクリックすると、そのボタンを無効にしたいと考えています。次のように私のコードは、..です
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
}
});
しかし、エラーが表示されます。local variable letter Button is accessed from the inner class; needs to be declared final
は...それは何を意味するのでしょうか?どうすれば問題を解決できますか? ありがとうございました...
可能な複製:http://stackoverflow.com/questions/1299837/cannot-refer-to-a-non-final-variable-inside-an-inner-class-defined-in-a - 異なる –