简体   繁体   中英

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?

Add this two lines top of your class :

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM