I am trying to access in an inner class (actionListener) a variable that changes value in the main class. I can't make it final, because it changes values before the actionListener triggered.
Have anyone met the same problem?
Thank you
public class MyClass{
private int counter = 0;
public void myMethod(){
//read from file
//counter = number of lines of the file read
JButton button = new JButton ("My button");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("lines = " +counter);
}
});
}
}