Construct the GUI
JButton b;
f = new JFrame("Score");
JMenuBar mb = new JMenuBar();
JMenuItem mi;
JMenu fm = new JMenu("File");
fm.add(mi = new JMenuItem("Quit"));
mi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.exit(0);
}
});
mb.add(fm);
JMenu em = new JMenu("Edit");
em.add(mi = new JMenuItem("Reset"));
mi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
lst.setText(df.format(0));
rst.setText(df.format(0));
}
});
mb.add(em);
f.setJMenuBar(mb);
Container cp = f.getContentPane();
cp.setLayout(new FlowLayout());
Font bigF = new Font("helvetica", Font.BOLD, 128);
cp.add(lst = new JTextField(df.format(0)));
lst.setFont(bigF);
cp.add(b = new JButton("+"));
b.addActionListener(new Adder(lst, 1));
cp.add(rst = new JTextField(df.format(0)));
rst.setFont(bigF);
cp.add(b = new JButton("+"));
b.addActionListener(new Adder(rst, 1));
f.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
//System.out.println(e);
switch(e.getKeyChar()) {
case 'l": case 'L": incr(lst); break;
case 'r": case 'R": incr(rst); break;
// XXX "Q" should require a JOptionPane confirmation...
case 'Q": System.exit(0); break;
}
}
});
f.pack();