Why do you have to override all methods of an interface?
For instance if I have
public class Foo extend JFrame implements ActionListener, KeyListener {
Concrete classes must always implement all of the methods of an interface. If you weren't already extending JFrame
you could extend KeyAdapter
. It implements empty methods for KeyListener
to avoid writing them out. You could use an anonymous class with that inside of your Foo
class like this:
addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
// handle typed key here
}
});