-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminWindow.java
More file actions
65 lines (58 loc) · 1.9 KB
/
AdminWindow.java
File metadata and controls
65 lines (58 loc) · 1.9 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
/*
this should give option to add and delete users
what does deleting a user do to conversations they're involved in?
maybe it says "[rip] sent: "
could have a list of users
add/remove buttons
might allow read of any convo O_o
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AdminWindow {
String windowName = "Admin";
Server host;
AdminWindow(Server h){
host=h;
JFrame frame = new JFrame(windowName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setLocationRelativeTo(null);
JPanel p = new JPanel(new BorderLayout());
JPanel buttonPanel = new JPanel();
Button addUserB = new Button("Add User");
addUserB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
h.addUser(new User(JOptionPane.showInputDialog(frame,
"Enter the user's name.",null),h ));
}
});
Button deleteUserB = new Button("Delete User");
deleteUserB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String[] possibilities = h.ListUsernames();
String s = (String)JOptionPane.showInputDialog(
frame,
"Choose user to delete.",
"Delete User",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
null);
//tell windowmanager to close userr's windows
//each jframe will close
h.deleteUser(s);
}
});
buttonPanel.add(addUserB);
buttonPanel.add(deleteUserB);
p.add(buttonPanel, BorderLayout.CENTER);
JPanel userListPanel = new JPanel();
p.add(userListPanel, BorderLayout.WEST);
frame.add(p);
frame.setVisible(true);
}
}