So right now I have the following:
public class Panel extends JPanel {
int size;
public Panel()
{
    JButton newBut = new JButton();
    newBut.addActionListener(new ActionListener()
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            boolean validInput = false;
            while (!validInput)
            {
                String input = JOptionPane.showInputDialog("Please specify a number:");
                try{
                    size = Integer.parseInt(input);
                    validInput = true;
                } catch (NumberFormatException ex){
                    JOptionPane.showMessageDialog(new JFrame(), "Invalid Input!", "ERROR",JOptionPane.ERROR_MESSAGE);
                }
                if (input == null)
                {
                    validInput = true;
                }
            }
        }
    });
}
Now as you can see from the code, I am trying to parse the input from the user as an integer, and then store that value inside my global variable "size". However, when I try to do this I get the error:
Cannot refer to a non-final variable inside an inner class defined in a different method
Setting size to final is not an option for me, since I need size to be able to change each time the user inputs a new value. So I honestly have no idea how I'm supposed to retrieve the size variable from the inner method. Any help would be mightily appreciated.
 
     
     
    