/* ButtonUI.java * * Simple Event-Driven GUI Application * Derived from: EventExampleUI.java */ import java.awt.*; import java.awt.event.*; import corejava.*; public class ButtonUI extends CloseableFrame implements ActionListener { Label valueLabel; Button incrementButton; Button resetButton; public ButtonUI() { initialize(); } private void initialize() { setSize(240, 100); // 240 was 200 this.setLayout(null); incrementButton = new Button("Increment"); //incrementButton.setBounds(20, 40, 75, 25); incrementButton.setBounds(20, 40, 100, 25); // 100 was 75 incrementButton.addActionListener(this); add(incrementButton); resetButton = new Button("Reset"); //resetButton.setBounds(105, 40, 75, 25); resetButton.setBounds(125, 40, 100, 25); // 125 was 105, 100 was 75 resetButton.addActionListener(this); add(resetButton); valueLabel = new Label("0", Label.CENTER); valueLabel.setBounds(95, 70, 50, 25); // 95 was 75 add(valueLabel); setVisible(true); } public void actionPerformed( ActionEvent evt ) { if (evt.getSource() == incrementButton) { int value = (new Integer(valueLabel.getText())).intValue(); valueLabel.setText(String.valueOf(value + 1)); } else if (evt.getSource() == resetButton) valueLabel.setText("0"); } public static void main( String[] args ) { new ButtonUI(); } }