title: Trying to add a bunch of action listeners
body: <p>I'm trying to give my buttons all their own action listener but I keep getting a weird error</p>
  
  <p>"No enclosing instance of type Buttons is accessible. Must qualify the allocation with an enclosing instance of type Buttons (e.g. x.new A() where x is an instance of Buttons)."</p>
  
  <p>On the line where I add the first Action Listener.
  Any solutions or ideas are greatly appreciated.</p>
  
  <p>Here is my code</p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.*;
  
  public class Buttons
  {
  static int numPress = 0;
  static int n = 0;
  static int fromX;
  static int fromY;
  static int toX;
  static int toY;
  static JButton button[] = new JButton[15];
  static int[][] mult = new int[][]
          {
              {0, 1, 1, 1, 1},
              {0, 1, 1, 1, 1},
              {0, 0, 1, 1, 1},
              {0, 0, 0, 1, 1},
              {0, 0, 0, 0, 1}
          };
  
  public static void main(String []args)
  {
      pegGame game = new pegGame();
      JFrame f = new JFrame("Button");
      int row = 5;
      int size = 50;
      for (int j = 1; j &lt;= row; j++)
      {
          for (int i = 0; i &lt; j; i++)
          {
              button[n] = new JButton();
              button[n].setBounds((size*row/2 + i*size - j*size/2),size*j - size,size,size);
              f.add(button[n]);
              numPress++;
              n++;
          }
      }
      bttnTxt();
  
      button[0].addActionListener(new btn0());
      button[1].addActionListener(new btn1());
      button[2].addActionListener(new btn2());
      button[3].addActionListener(new btn3());
      button[4].addActionListener(new btn4());
      button[5].addActionListener(new btn5());
      button[6].addActionListener(new btn6());
      button[7].addActionListener(new btn7());
      button[8].addActionListener(new btn8());
      button[9].addActionListener(new btn9());
      button[10].addActionListener(new btn10());
      button[11].addActionListener(new btn11());
      button[12].addActionListener(new btn12());
      button[13].addActionListener(new btn13());
      button[14].addActionListener(new btn14());
  
      f.setSize(row*size,row*size);
      f.setLayout(null);
      f.setVisible(true);
  }
  class btn0 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 0;
              fromY = 0;
              numPress++;
          } else{
              toX = 0;
              toY = 0;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn1 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 0;
              fromY = 1;
              numPress++;
          } else{
              toX = 0;
              toY = 1;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn2 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 1;
              fromY = 1;
              numPress++;
          } else{
              toX = 1;
              toY = 1;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn3 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 0;
              fromY = 2;
              numPress++;
          } else{
              toX = 0;
              toY = 2;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn4 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 1;
              fromY = 2;
              numPress++;
          } else{
              toX = 1;
              toY = 2;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn5 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 2;
              fromY = 2;
              numPress++;
          } else{
              toX = 2;
              toY = 2;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn6 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 0;
              fromY = 3;
              numPress++;
          } else{
              toX = 0;
              toY = 3;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn7 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 1;
              fromY = 3;
              numPress++;
          } else{
              toX = 1;
              toY = 3;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn8 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 2;
              fromY = 3;
              numPress++;
          } else{
              toX = 2;
              toY = 3;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn9 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 3;
              fromY = 3;
              numPress++;
          } else{
              toX = 3;
              toY = 3;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn10 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 0;
              fromY = 4;
              numPress++;
          } else{
              toX = 0;
              toY = 4;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn11 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 1;
              fromY = 4;
              numPress++;
          } else{
              toX = 1;
              toY = 4;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn12 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 2;
              fromY = 4;
              numPress++;
          } else{
              toX = 2;
              toY = 4;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn13 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 3;
              fromY = 4;
              numPress++;
          } else{
              toX = 3;
              toY = 4;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  class btn14 implements ActionListener
  {
      public void actionPerformed(ActionEvent x) 
      {
          if(numPress == 0)
          {
              fromX = 4;
              fromY = 4;
              numPress++;
          } else{
              toX = 4;
              toY = 4;
              moveCheck(fromX, fromY, toX, toY);
          }
      }
  }
  
  public static void moveCheck(int fromX, int fromY, int toX, int toY)
  {
      if (mult[toX][toY] == 0 &amp;&amp; mult[fromX][fromY] == 1)
      {
          if (fromX + 2 == toX &amp;&amp; fromY + 2 == toY &amp;&amp; mult[toX][toY] == 0 &amp;&amp; mult[fromX + 1][fromY + 1] == 1)
          {
              mult[fromX][fromY] = 0;
              mult[(fromX + 1)][(fromY + 1)] = 0;
              mult[toX][toY] = 1;
          } else if(fromX - 2 == toX &amp;&amp; fromY - 2 == toY &amp;&amp; mult[fromX - 1][fromY - 1] == 1)
          {
              mult[fromX][fromY] = 0;
              mult[(fromX - 1)][(fromY - 1)] = 0;
              mult[toX][toY] = 1;
          } else if(fromX + 2 == toX &amp;&amp; fromY == toY &amp;&amp; mult[fromX + 1][fromY] == 1)
          {
              mult[fromX][fromY] = 0;
              mult[fromX + 1][fromY] = 0;
              mult[toX][toY] = 1;
          } else if(fromX - 2 == toX &amp;&amp; fromY == toY &amp;&amp; mult[fromX - 1][fromY] == 1)
          {
              mult[fromX][fromY] = 0;
              mult[fromX - 1][fromY] = 0;
              mult[toX][toY] = 1;
          }else if(fromY + 2 == toY &amp;&amp; fromX == toX &amp;&amp; mult[fromX][fromY + 1] == 1)
          {
              mult[fromX][fromY] = 0;
              mult[fromX][fromY + 1] = 0;
              mult[toX][toY] = 1;
          }else if(fromY - 2 == toY &amp;&amp; fromX == toX &amp;&amp; mult[fromX][fromY - 1] == 1)
          {
              mult[fromX][fromY] = 0;
              mult[fromX][fromY - 1] = 0;
              mult[toX][toY] = 1;
          }else
          {
              JOptionPane.showMessageDialog(null, "Please pick a legal move");
          }
      }else
      {
          JOptionPane.showMessageDialog(null, "Please pick a legal move");
      }
      bttnTxt();
      numPress = 0;
  }
  public static void bttnTxt()
  {
      button[0].setText(Integer.toString(mult[0][0]));
      button[1].setText(Integer.toString(mult[0][1]));
      button[2].setText(Integer.toString(mult[1][1]));
      button[3].setText(Integer.toString(mult[0][2]));
      button[4].setText(Integer.toString(mult[1][2]));
      button[5].setText(Integer.toString(mult[2][2]));
      button[6].setText(Integer.toString(mult[0][3]));
      button[7].setText(Integer.toString(mult[1][3]));
      button[8].setText(Integer.toString(mult[2][3]));
      button[9].setText(Integer.toString(mult[3][3]));
      button[10].setText(Integer.toString(mult[0][4]));
      button[11].setText(Integer.toString(mult[1][4]));
      button[12].setText(Integer.toString(mult[2][4]));
      button[13].setText(Integer.toString(mult[3][4]));
      button[14].setText(Integer.toString(mult[4][4]));
  }
  public static boolean checkWin()
  {
      int count = 0;
      for(int i = 0; i &lt; mult.length; i++)
      {
          for(int j = 0 ; j &lt; mult.length; j++)
          {
              if(mult[i][j] != 0)
              {
                  count ++;
              }
          }
      }
      if (count &gt; 1)
      {
          count = 0;
      } else
      {
          JOptionPane.showMessageDialog(null, "You Win!");
      }
      return false;
  }
  }
  </code></pre>