forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetterListener.java
More file actions
38 lines (32 loc) · 1.16 KB
/
BetterListener.java
File metadata and controls
38 lines (32 loc) · 1.16 KB
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
36
37
38
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class BetterListener extends JFrame {
private class HelloListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("Hello was pressed.");
}
}
private class GoodByeListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("Good bye was pressed.");
}
}
public BetterListener() {
super("Better Listener");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton helloButton = new JButton("Hello");
helloButton.addActionListener(new HelloListener());
JButton goodByeButton = new JButton("Good bye");
goodByeButton.addActionListener(new GoodByeListener());
add(helloButton, BorderLayout.NORTH);
add(goodByeButton, BorderLayout.SOUTH);
}
public static void main(String[] args) {
BetterListener better = new BetterListener();
better.pack();
better.setVisible(true);
}
}