forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounterFrame.java
More file actions
35 lines (28 loc) · 971 Bytes
/
CounterFrame.java
File metadata and controls
35 lines (28 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class CounterFrame extends JFrame {
public CounterFrame() {
super("Counter");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton exitButton = new JButton("Exit");
exitButton.addActionListener(new ExitListener());
JLabel counterLabel = new JLabel("Count: 0");
JButton counterButton = new JButton("Increment count");
counterButton.addActionListener(new CountListener(counterLabel));
setLayout(new GridLayout(3, 1));
add(counterLabel);
add(counterButton);
add(exitButton);
pack();
}
public static void main(String[] args) {
CounterFrame cf = new CounterFrame();
cf.setVisible(true);
}
}