When I need a key listener in java and just need to listen for a keyPressed event, why is it that both the keyReleased and keyTyped method need to be overridden in addiiton to the only method I really need? Is this meant to guard against errors?
Thanks,
emus
Stuka
10-17-2003, 12:28 PM
KeyListener is an interface - you MUST override all the definitions in an interface, as there is no 'default' implementation. If you want to have it easier, rather than implementing KeyListener, you can extend KeyAdapter (which implements KeyListener with all empty methods). There is, AFAIK, an 'Adapter' class like this for every 'Listener' interface.
Thank you very much Stuka, I'll read up on KeyAdapters.