Q:

Actionevent final variables? 

I have the following code and i get an error at line 19 "cannot assign a value to a final variable count", but i have to assign this variable as final in order to use it in the "LISTENER".   Where is the mistake ? 
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);
    }
}

A:

A  final variable cannot be modified once it has been assigned.  The solution is to make the variable a member of your ClickListener class:
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);

        class ClickListener implements ActionListener
        {
            int count = 0;
            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);
    }
}

