There are some examples here:
How to Write a Key Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
Start with a simple program that catches key events and...