forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBadListener.java
More file actions
34 lines (30 loc) · 1.06 KB
/
BadListener.java
File metadata and controls
34 lines (30 loc) · 1.06 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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class BadListener extends JFrame implements ActionListener {
public BadListener() {
super("Bad");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton helloButton = new JButton("Hello");
helloButton.addActionListener(this);
JButton goodByeButton = new JButton("Good bye");
goodByeButton.addActionListener(this);
add(helloButton, BorderLayout.NORTH);
add(goodByeButton, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e) {
String button = e.getActionCommand();
if (button.equals("Hello")) {
System.out.println("Hello was perssed.");
} else if (button.equals("Good bye")) {
System.out.println("Good bye was perssed.");
}
}
public static void main(String[] args) {
BadListener bad = new BadListener();
bad.pack();
bad.setVisible(true);
}
}