title: Getting error using nested ActionListener class for a JButton Object?
body: <p>It's my first time trying to use action listeners and event-handling. I'm trying to create a simple GUI that has 3 buttons: <code>home</code>, <code>about</code> and <code>tag</code>. For each <code>JButton</code> I've added a listener object and created a nested class for the listener object.</p>
  
  <pre><code>public class interfacetest {
  
      public static void main(String[] args) {
  
          JFrame window = new JFrame("GUI Test");
          window.setSize(250, 100);
          window.setLocation(100, 100);
  
          final JButton home = new JButton("Home");
          final JButton about = new JButton("About");
          final JButton tag = new JButton("Tag");
  
          JMenuBar menu = new JMenuBar();
          menu.add(home);
          menu.add(about);
          menu.add(tag);
          menu.setVisible(true);
          window.setJMenuBar(menu);
  
          window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          thehandler handler = new thehandler();
          home.addActionListener(handler);
          about.addActionListener(handler);
          tag.addActionListener(handler);
  
          window.setVisible(true);
      }
  
      // Here is my nested class.
  
      private class thehandler implements ActionListener {
  
          public void actionPerformed(ActionEvent event) {
  
              String string = "";
              if (event.getSource()==home)
                  string = string.format("home: %s, event.getActionCommand()");
              else if (event.getSource()==about)
                  string = string.format("about: %s, event.getActionCommand()");
              else if (event.getSource()==tag) string = string.format("tag: %s, event.getActionCommand()");
              JOptionPane.showMessageDialog(null, string);
          }
      }
  }
  </code></pre>
  
  <p><strong>I'm getting the error when I'm creating a new <code>thehandler</code> object saying:</strong> <em>"No enclosing instance of type interfacetest is accessible. Must qualify the allocation with an enclosing instance of type interfacetest (e.g. x.new A() where x is an instance of interfacetest)."</em></p>