-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
107 lines (95 loc) · 3.45 KB
/
Client.java
File metadata and controls
107 lines (95 loc) · 3.45 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
this one may be unnecessary
but i think it could:
let users start chats and designate participants
let users access user settings
(change name, delete account)
might even let users set stati, idk tho seems unnecessary
would be both controller and view?
*/
import javax.swing.*;
import java.util.Random;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Client {
String windowName;
User user;
Server host;
Client(User u, Server h) {
user = u;
windowName = "User: " + user.getName();
host = h;
drawClientWindow();
}
public void drawClientWindow() {
JFrame frame = new JFrame(windowName);
frame.setSize(500,100);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
JPanel p = new JPanel(new FlowLayout());
Button startChatB = new Button("Start chat");
startChatB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ParticipantGroup participants = new ParticipantGroup();
JFrame participantSelector = new JFrame("Start chat");
participantSelector.setSize(500,300);
JList<String> userList = new JList<>(host.ListUsernames(user));
userList.setSize(100,100);
userList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JOptionPane.showMessageDialog(null,new JScrollPane(userList));
participants.addParticipant(user);
for (String s : userList.getSelectedValuesList()) {
participants.addParticipant(host.getUser(s));
}
startChat(participants);
}
});
p.add(startChatB);
Button editUserSettingsB = new Button("Edit settings");
editUserSettingsB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame userSettings = new JFrame("User Settings: "+user.getName());
JPanel us = new JPanel(new FlowLayout());
userSettings.setSize(500,100);
Button changeNameB = new Button("Change name");
changeNameB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newName = JOptionPane.showInputDialog(frame,
"Enter your changed name.",user.getName());
user.setName(newName);
}
});
Button deleteUserB = new Button("Delete account");
deleteUserB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(0==JOptionPane.showConfirmDialog(frame,"Are you sure you want to delete?",
"Confirm delete",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null)) {
host.deleteUser(user);
//////////////////////
//close user's windows
//////////////////////
}
}
});
us.add(changeNameB);
us.add(deleteUserB);
userSettings.add(us);
userSettings.setVisible(true);
}
});
p.add(editUserSettingsB);
frame.add(p);
Random rand = new Random();
int random_x = rand.nextInt(1000);
int random_y = rand.nextInt(700);
frame.setLocation(random_x,random_y);
frame.setVisible(true);
}
public void startChat(ParticipantGroup p) {
host.hostChat(p, user);
}
}