Slurba
Slurba

Reputation: 37

Why isnt ActionListener working?

Why isn't this ActionListener working? I've tried to follow tutorials but I keep getting the same error.

public class listenerTest implements ActionListener {
@Override //<-- This adds another error
public void actionPerformed(ActionEvent e) 
{
    System.out.println("Message"+e.toString());
    System.exit(0);
}
}

And in the other file:

loginButton.addActionListener(new listenerTest());

NetBeans says

there are compilation errors on listenerTest class "listenerTest is not abstract and 
does not override abstract method actionPerformed(ActionEvent) in ActionListener"` 

and the error on @Override says method does not override or implement a method from supertype.

Any help how to fix this?

Upvotes: 0

Views: 65

Answers (2)

Slurba
Slurba

Reputation: 37

I had mixed up JavaFX and AWT ActionEvent imports. Thanks, @Reimeus!

Upvotes: 1

lutfucan
lutfucan

Reputation: 151

Add this two lines top of your class :


    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

Upvotes: 1

Related Questions