title: Referencing from an inner class
body: <p>I have the following code</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import net.miginfocom.swing.MigLayout;
  import Sorts.*;
  import javax.swing.event.*;
  import java.awt.event.*;
  import java.awt.Color;
  
  public class SortsGui
  {
      JFrame myMainWindow = new JFrame("Sorts");
  
      JPanel sortPanel = new JPanel();
  
      //first panel components
      public int nextTextBox = 20;
      JTextField[] allField = new JTextField [25];
      //end first panel
  
      public void runGUI()
      {
          myMainWindow.setBounds(10, 10, 800, 800);
          myMainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          myMainWindow.setLayout(new GridLayout(1,1));
  
          createSortTestPanel();
  
          myMainWindow.getContentPane().add(sortPanel);
  
          myMainWindow.setVisible(true);
      }
  
      public void createSortTestPanel()
      {
          MigLayout layout = new MigLayout("" , "[grow]");
          sortPanel.setLayout(layout);
  
          refreshScreen();
      }
  
      public void refreshScreen()
      {
          sortPanel.removeAll();
  
          for(int i = 0; i&lt;nextTextBox;i++)
          {
              int fix = i+1;
              allField[i] = new JTextField("");
              sortPanel.add(allField[i],"growx");
              allField[i].addKeyListener(new KeyListener ()
              {
                  public void keyPressed(KeyEvent e)
                  {
  
                  }
  
                  public void keyReleased(KeyEvent e)
                  {
  
                  }
  
                  public void keyTyped(KeyEvent e)
                  {
                      char c = e.getKeyChar();
                      if(Character.isDigit(c))
                      {
  
                      }
  
                      else 
                      {
                          e.consume();
                      }
  
                      try
                      {
                          int parseTest = Integer.parseInt(allField[i].getText());
                      }
  
                      catch(Exception exc)
                      {
                          allField[i].setBackground(Color.RED);
                      }
                  }
              });
          }
      }
  
      public static void main(String[] args)
      {
          SortsGui sG = new SortsGui();
          sG.runGUI();
      }
  }
  </code></pre>
  
  <p>My aim here is to create an array of JTextFields which have a keylistener on. This keylistener should prevent anything other than numbers being entered in the JTextField. It should also change the color of the JTextField's background if the number entered is not an int. For example 2147483647554.
  However when I compile this I get the error</p>
  
  <p><img src="https://i.stack.imgur.com/fthuy.png" alt="Inner class error"></p>
  
  <p>So how do I make this so that it is either final or effectively final on all the JTextFields?</p>