-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathName.java
More file actions
90 lines (74 loc) · 1.92 KB
/
Copy pathName.java
File metadata and controls
90 lines (74 loc) · 1.92 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Programmer: Edgar Colin
// Student ID: EDG2140344
// Class: CIS263AA JAVA II Class # 12303
// Instructor: Michael Parmeley
// Chapter: 14
// Problem: 1
// Part:
// Filename: Name.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Name extends
JFrame implements ActionListener
{
JButton nameBob = new JButton("Bob");
JButton nameSally = new JButton("Sally");
JButton nameMike = new JButton("Mike");
JButton nameAlice = new JButton("Alice");
JButton nameTom = new JButton("Tom");
JTextField nameBox = new JTextField(14);
String selected = "";
public Name()
{
super("List of Names");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
add(nameBob);
add(nameSally);
add(nameMike);
add(nameAlice);
add(nameTom);
add(nameBox);
nameBox.setText(selected );
nameBob.addActionListener(this);
nameSally.addActionListener(this);
nameMike.addActionListener(this);
nameAlice.addActionListener(this);
nameTom.addActionListener(this); // Item or Action Listener
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source == nameBob)
{
selected = "Bob";
}
else if ( source == nameSally)
{
selected = "Sally";
}
else if ( source == nameMike)
{
selected = "Mike";
}
else if ( source == nameAlice)
{
selected = "Alice";
}
else if ( source == nameTom)
{
selected = "Tom";
}
nameBox.setText(selected);
}
public static void main(String[] args)
{
Name aFrame =
new Name();
final int WIDTH = 300;
final int HEIGHT = 200;
aFrame.setSize(WIDTH, HEIGHT);
aFrame.setVisible(true);
}
}