001    package gizmoball;
002    
003    import javax.swing.*;
004    import java.awt.event.*;
005    
006    public class KeypressTest {
007      public static void main(String[] args) {
008        JFrame jf = new JFrame();
009        jf.getContentPane().add(new JLabel("Make sure this window has focus, then hit some keys"));
010        jf.getContentPane().add(new JLabel("CTRL-C at your console to quit"));
011        jf.addKeyListener( new KeyListener() {
012            public void keyPressed(KeyEvent e) {
013              System.out.println("PRESSED " + e);
014            }
015            public void keyReleased(KeyEvent e) {
016              System.out.println("RELEASED " + e);
017            }
018            public void keyTyped(KeyEvent e) {
019              // You are probably not interested in typed events
020              // System.out.println("TYPED " + e);
021            }
022          } );
023        jf.setSize(400, 400);
024        jf.setVisible(true);
025      }
026    }