Hi all,
Having some issues with ActionListener in Swing, I have added an actionListener to a button, and it works as expected, but if I try to change any variables, I get a "local variable is accessed from within inner class, needs to be declared Final".
Any ideas? If I want my button to, for instance, decrement an int variable, everytime it's pressed, the int can't possibly be declared as final.
Here's a snippet of my code:
Thanks!Code:int currentHealth = 100;
JPanel mainPanel = new JPanel();
final JLabel label1 = new JLabel(Integer.toString(currentHealth));
JButton okButton = new JButton("OK");
JButton cancelButton = new JButton("CANCEL");
JButton exitButton = new JButton("Exit");
JFrame mainFrame = new JFrame("Application");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//OK Button event
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent ae){
currentHealth = CurrentHealth--; //ERROR HERE
System.out.println("Button Pressed");
}
};

