import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

    // Two JButtons (Go and Stop) control a horizontal JProgressBar.
    // Used mainly as an example of the former.
class SwingButtonFrame extends JFrame {
    public SwingButtonFrame(){
        final int width = 300, height = 100;
        setSize(width,height);
        Container contents = getContentPane();

        // The reaction timer, which is a progress bar.
        final ReactionTimer reaction =
                        new ReactionTimer(JProgressBar.HORIZONTAL);

        // The two buttons that will manipulate the timer.
        final AbstractButton go = new JButton("Go",new ImageIcon("Go.gif"));
        final AbstractButton stop = new JButton("Stop",new ImageIcon("Stop.gif"));
        // Enable the go button, and attach key mnemonics to both.
        go.setEnabled(true);
        go.setMnemonic('g');
        stop.setEnabled(false);
        stop.setMnemonic('s');

        // When the go button is pressed, it must start the timer
        // and enable the stop button.
        go.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                go.setEnabled(false);
                reaction.start();
                stop.setEnabled(true);
            }
        });

        // When the stop button is pressed, it must stop the timer
        // and enable the go button.
        stop.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                reaction.stop();
                stop.setEnabled(false);
                go.setEnabled(true);
            }
        });

        // Group the two buttons.
        JPanel buttonPanel = new JPanel();
        buttonPanel.add(go);
        buttonPanel.add(stop);

        contents.add(reaction,"Center");
        contents.add(buttonPanel,"South");
    }
}
