UNB/ CS/ David Bremner/ teaching/ java/ CounterFrame.java
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
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 javax.swing.JTextField;

public class CounterFrame extends JFrame  implements ActionListener {

    private JButton decrease=new JButton("Decrease");
    private JButton increase=new JButton("Increase");
    private int fieldValue=0;
    private JTextField status=new JTextField(15);



    // 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()==increase){
            fieldValue++;
        } else {
            fieldValue--;
        }
        status.setText(""+fieldValue);
    }
        
    
    public CounterFrame(){
        init();
    }

    public void init(){
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(decrease);
        getContentPane().add(increase);

        increase.addActionListener(this);
        decrease.addActionListener(this);
        status.setEditable(false);
        status.setText("0");
        getContentPane().add(status);
    }

    public static void main(String[] args){

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

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

//