次のコードがあり、19行目で「最終変数カウントに値を割り当てることができません」というエラーが表示されますが、「LISTENER」で使用するには、この変数を最終変数として割り当てる必要があります。間違いはどこにありますか?
import java.awt.event.*;
import javax.swing.*;
public class ButtonTester
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
JButton button = new JButton();
frame.add(button);
final int count = 0;
class ClickListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
count++;
System.out.println("I was clicked " + count + " times");
}
}
ActionListener listener = new ClickListener();
button.addActionListener(listener);
frame.setSize(100,60);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}