KeyListener

I try to interface the KeyListener through a class like so:


public class KeyDisplay implements GLEventListener, MouseListener, KeyListener
{
     .......
     .......
     .......
}

I get the following compile error at the class declaration:

  • KeyDisplay is not abstract and does not override abstract method keyReleased(java.awt.event.KeyEvent) in java.awt.event.KeyListener

Does anyone know what the problem is, I want to have a MouseListener as well as a KeyListener.

It sounds like you’ve neglected to provide an implementation for keyReleased( Keyevent ) method defined in the KeyListener class.

Non-abstract classes must provide an body for every methods defined in the interfaces they implement.

If you think you have provided such a method, there’s probably a tiny typo in the method name, like keyreleased() or something.

when you implement an interface, you must override all of its methods, even if you don’t plan to use them. In this specific instance, you need to add this method to your code:


public void keyReleased(KeyEvent e) {
	// nothing...
}

The compiler may still nag at you for more methods you haven’t implemented because it only nags about one at a time. You can get the full list of methods KeyListener requires you to override in the docs: KeyListener API

Thanks, question was answered, that is exactly what the problem is.