UNB/ CS/ David Bremner/ teaching/ java/ KeyFrame.java
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.FlowLayout;
import java.util.Date;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;

public class KeyFrame extends JFrame  implements KeyListener, ActionListener {

    private JButton type=new JButton("Type");
    private JButton quit=new JButton("Quit");

    private JTextArea status=new JTextArea(15,20);
    private long lastTime=0;
    private final int PATIENCE_THRESHOLD=5000;


    // Implementation of java.awt.event.ActionListener

    /**
     * Print a silly message, and event time.
     *
     * @param actionEvent an <code>ActionEvent</code> value
     */
    public void actionPerformed(ActionEvent actionEvent) {

        if (actionEvent.getSource()==quit){
            System.exit(0);
        } else {
            getContentPane().requestFocus();
        }
    }
        
    
    public KeyFrame(){
        init();
    }

    public void init(){
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(quit);
        getContentPane().add(type);

        type.addActionListener(this);
        quit.addActionListener(this);
        status.setEditable(false);
        getContentPane().addKeyListener(this);
        status.setLineWrap(true);
        //      getContentPane().add(status);
        getContentPane().add(new JScrollPane(status));
    }

    // Implementation of java.awt.event.KeyListener

    /**
     * Describe <code>keyTyped</code> method here.
     *
     * @param keyEvent a <code>KeyEvent</code> value
     */
    public void keyTyped(KeyEvent keyEvent) {
        status.append(""+keyEvent.getKeyChar());
    }

    /**
     * Describe <code>keyPressed</code> method here.
     *
     * @param keyEvent a <code>KeyEvent</code> value
     */
    public void keyPressed(KeyEvent keyEvent) {
        // do nothing
    }

    /**
     * Describe <code>keyReleased</code> method here.
     *
     * @param keyEvent a <code>KeyEvent</code> value
     */
    public void keyReleased(KeyEvent keyEvent) {
        // do nothing
    }
    
    public static void main(String[] args){

        KeyFrame f=new KeyFrame();
        f.setSize(400,300);
        f.setVisible(true);

        f.addWindowListener(
                            new WindowAdapter() {
                                public void windowClosing(WindowEvent e) { System.exit(0);}});
                            
    }
}