forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreetingFrame.java
More file actions
33 lines (27 loc) · 952 Bytes
/
GreetingFrame.java
File metadata and controls
33 lines (27 loc) · 952 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
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class GreetingGui extends JFrame implements ActionListener {
private JLabel greetingLabel;
public GreetingGui() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
greetingLabel = new JLabel("Greeting will go here.");
JButton button = new JButton("Greet!");
button.addActionListener(this);
add(greetingLabel, BorderLayout.CENTER);
add(button, BorderLayout.SOUTH);
pack();
}
public void actionPerformed(ActionEvent e) {
Greeter greeter = new Greeter("bob");
String greeting = greeter.greet();
greetingLabel.setText(greeting);
}
public static void main(String[] args) {
GreetingGui gg = new GreetingGui();
gg.setVisible(true);
}
}