forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounterWindow.java
More file actions
29 lines (23 loc) · 985 Bytes
/
CounterWindow.java
File metadata and controls
29 lines (23 loc) · 985 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
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class CounterWindow {
public static void main(String[] args) {
JFrame mainFrame = new JFrame("Counter");
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainFrame.setLayout(new BorderLayout());
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));
mainFrame.add(counterButton, BorderLayout.NORTH);
mainFrame.add(counterLabel, BorderLayout.CENTER);
mainFrame.add(exitButton, BorderLayout.SOUTH);
mainFrame.setSize(200, 300);
mainFrame.setVisible(true);
}
}