forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloButtons.java
More file actions
30 lines (24 loc) · 947 Bytes
/
HelloButtons.java
File metadata and controls
30 lines (24 loc) · 947 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
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class HelloButtons {
public static void main(String[] args) {
JFrame mainFrame = new JFrame("Hello, buttons!");
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainFrame.setLayout(new FlowLayout());
JButton exitButton = new JButton("Exit");
exitButton.addActionListener(new ExitListener());
JLabel counterLabel = new JLabel("Count: 0");
JButton counterButton = new JButton("Increment count");
CountListener cl = new CountListener(counterLabel);
counterButton.addActionListener(cl);
mainFrame.add(exitButton);
mainFrame.add(counterButton);
mainFrame.add(counterLabel);
mainFrame.pack();
mainFrame.setVisible(true);
}
}