Results 1 to 3 of 3
  1. #1
    isaacske is offline Member
    Join Date
    Sep 2012
    Rep Power

    Exclamation Why is my ActionListener not working

    My Button with its ActionListener

    Java Code:
    JButton buttonComponent = new JButton("Button");
    buttonComponent.addActionListener(new newButtonAction()); // THIS BIT SAYS ITS NOT CORRECT
    ActionListener code

    Java Code:
    public class newButtonAction implements ActionListener {
    	public void actionPerformed(ActionEvent e) {
    		JOptionPane buttonOptionPane = new JOptionPane("Creating a Button");
    This is what eclipse is saying to me...

    No enclosing instance of type AppName is accessible. Must qualify the allocation with an enclosing instance of type AppName (e.g. A() where x is an instance of App Name).

    Please help me. I have looked all over the internet to find out how but they are saying that my one should work.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power

    Default Re: Why is my ActionListener not working

    You should write the ActionListener class "newButtonAction" into a new file named newButtonAction (please read about code convntions!!!)
    Maybe you could also use buttonComponent.addActionListener( newButtonAction()); instead of buttonComponent.addActionListener(new newButtonAction()); but

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Why is my ActionListener not working

    Code Conventions for the Java Programming Language: Contents

    Class names should start with an uppercase letter.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. actionlistener no working,, help
    By SaraDiab in forum Advanced Java
    Replies: 2
    Last Post: 12-27-2011, 06:22 AM
  2. Replies: 2
    Last Post: 01-04-2011, 05:30 AM
  3. JButton actionlistener not working, very strange
    By alacn in forum New To Java
    Replies: 4
    Last Post: 08-05-2010, 03:25 AM
  4. ActionListener NOT working
    By zed420 in forum New To Java
    Replies: 3
    Last Post: 12-20-2009, 04:40 PM
  5. Replies: 8
    Last Post: 05-28-2008, 08:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts