title: JButton and ActionListener causing many run-time errors
body: <p>So I am trying to make a version of Conway's Game of Life using Eclipse and JSwing, 
  my issue is when I attempt to start the code to run a generation it instead produces a large amount of runtime errors The issue arises when I attempt to press the first JButton which I am currently using as a start button for the next generation of the simulation. The Cell class is just a set of setters and getters for both its current state and its place in the array of buttons, The list of errors that occur when I press the first button are below the code</p>
  
  <pre><code>public class MainPage extends JFrame implements ActionListener{
  
  JButton[] screen = new JButton[2500]; 
  JButton start = new JButton("Start");
  Cell[] cells = new Cell[2500];
  int select = 0;
  
  public static void main(String args[]) {
  
      new MainPage();
  
  }
  
  public MainPage() {
      super("The Game Of Life");
      int k = 0;
      while (k &lt; 2500) {
          screen[k] = new JButton("");
          screen[k].setBackground(Color.BLACK);
          cells[k] = new Cell(k);
          cells[k].setState(0);
          k++;
      }
  
      Container surface = this.getContentPane();
      surface.setLayout(new GridLayout(50,50));
  
      // k == row j == col
      for (int i = 0; i &lt; 2500; i++) {
  
             int finalI = i; // no final modifier
              surface.add(screen[i]);
  
              screen[i].addActionListener(e -&gt; {
  
  
                  Color color = screen[finalI].getBackground();
                  if (color == Color.BLACK)
                  {
                      screen[finalI].setBackground(Color.WHITE);
                      cells[finalI].setState(1);
                  }
                  else {
                      screen[finalI].setBackground(Color.BLACK);
                      cells[finalI].setState(0);
                  }
  
              });
              screen[0].addActionListener(this);
  
      }
  
      this.pack();
      this.setVisible(true);
  
  
  }
  public void setnewstates() {
      int k = 51;
      int screensize = 50;
  
      while (k &lt; 2500 || k &gt; 50 || k % 50 != 0 || (k + 1) % 50 != 0) // avoid borders for now
      {
          int neighbors = 0;
          int state = cells[k].getState();
          neighbors = cells[k - 1].getState() + neighbors; // check neighbors
          neighbors = cells[k + 1].getState() + neighbors;
          neighbors = cells[k + screensize].getState() + neighbors;
          neighbors = cells[k - screensize].getState() + neighbors;
          neighbors = cells[k + screensize + 1].getState() + neighbors;
          neighbors = cells[k + screensize - 1].getState() + neighbors;
          neighbors = cells[k - screensize - 1].getState() + neighbors;
          neighbors = cells[k - screensize + 1].getState() + neighbors;   
  
          if (state == 1) {
              if (neighbors &lt; 2)
              {
                  cells[k].setState(0);
                  screen[k].setBackground(Color.BLACK);
              }
              if (neighbors &gt; 3)
              {
                  cells[k].setState(0);
                  screen[k].setBackground(Color.BLACK);
              }
          }
          else if (state == 0) {
              if (neighbors == 3)
              {
                  cells[k].setState(1);
                  screen[k].setBackground(Color.WHITE);
              }
          }
      k++;
      }
  }
  
  public void actionPerformed(ActionEvent e) {
      if (e.getSource() == screen[0])
      {
          setnewstates();
      }
  }
  }
  </code></pre>
  
  <p>And Here are the errors that occur when I press the first button</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
  at MainPage.setnewstates(MainPage.java:72)
  at MainPage.actionPerformed(MainPage.java:106)
  at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
  at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
  at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
  at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
  at java.awt.Component.processMouseEvent(Unknown Source)
  at javax.swing.JComponent.processMouseEvent(Unknown Source)
  at java.awt.Component.processEvent(Unknown Source)
  at java.awt.Container.processEvent(Unknown Source)
  at java.awt.Component.dispatchEventImpl(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
  at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
  at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Window.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  at java.awt.EventQueue.access$500(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue$4.run(Unknown Source)
  at java.awt.EventQueue$4.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>