Why is my ActionListener not working
My Button with its ActionListener
Code:
//CREATE A JBUTTON
JButton buttonComponent = new JButton("Button");
buttonComponent.addActionListener(new newButtonAction()); // THIS BIT SAYS ITS NOT CORRECT
ActionListener code
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.
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 :x:
Re: Why is my ActionListener not working