UNB/ CS/ David Bremner/ teaching/ java/ EventFrame.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;

public class EventFrame extends DBFrame  implements ActionListener {
    private long lastTime=0;
    private final int PATIENCE_THRESHOLD=5000;

    private JButton destroy=new JButton("Self Destruct");
    private JButton happy=new JButton("Be Happy");

    private JTextArea status=new JTextArea(15,20);

    // Implementation of java.awt.event.ActionListener

    // Implementation of java.awt.event.ActionListener

    /**
     * Print a silly message in the status bar, and dump event as string.
     *
     * @param actionEvent an <code>ActionEvent</code> value
     */


    public void actionPerformed(ActionEvent actionEvent) {
        long eTime=actionEvent.getWhen();

        if (actionEvent.getSource()==destroy){
            if (eTime-lastTime < PATIENCE_THRESHOLD){
                status.append("Chill out man. The end is nigh!\n");
            } else {
                lastTime=eTime;
                status.append("Initiating self destruct sequence at "+
                              new Date(lastTime).toString()
                              +"\n");
            }
        } else {
            lastTime=0;
        }
    }
    
    public EventFrame(){
        super(300,400);
        init();
    }

    public void init(){
        getContentPane().add(destroy);
        getContentPane().add(happy);

        destroy.addActionListener(this);
        happy.addActionListener(this);
        status.setEditable(false);
        status.setLineWrap(true);
        getContentPane().add(new JScrollPane(status));
        setVisible(true);
    }

    public static void main(String[] args){
        EventFrame f=new EventFrame();


    }
}
//