Consuming events

This key listener discards non-alphabetic events:

public class Alpha implements KeyListener {

    public void keyPressed(KeyEvent e) {
        if (! Character.isLetter(e.getKeyChar())) {
            Toolkit.getDefaultToolkit().beep();
            e.consume();
        }
    }

    public void keyReleased(KeyEvent e) {
        // empty
    }

    public void keyTyped(KeyEvent e) {
        // empty
    }
}


Slide 49 ©Copyright 1997 Jan Newmarch