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

    Exclamation Why is my ActionListener not working

    My Button with its ActionListener

    Java Code:
    //CREATE A JBUTTON
    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. x.new 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
    Location
    Germany
    Posts
    787
    Rep Power
    5

    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(this.new newButtonAction()); instead of buttonComponent.addActionListener(new newButtonAction()); but

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Why is my ActionListener not working

    Code Conventions for the Java Programming Language: Contents

    Class names should start with an uppercase letter.

    db
    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, 05:22 AM
  2. Replies: 2
    Last Post: 01-04-2011, 04:30 AM
  3. JButton actionlistener not working, very strange
    By alacn in forum New To Java
    Replies: 4
    Last Post: 08-05-2010, 02:25 AM
  4. ActionListener NOT working
    By zed420 in forum New To Java
    Replies: 3
    Last Post: 12-20-2009, 03:40 PM
  5. Replies: 8
    Last Post: 05-28-2008, 07: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
  •