-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatWindow.java
More file actions
91 lines (82 loc) · 2.86 KB
/
Copy pathChatWindow.java
File metadata and controls
91 lines (82 loc) · 2.86 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
package Chat;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
/**
*The chat window
* @author joar
*/
public class ChatWindow extends JFrame {
private Conversation conversation;
private View view;
private Controller controller;
/**
*Constructor for single conversation
* @param connection the instance of the TCP connection class
* @param socket The socket for the single conversation
* @param accepted boolean, client accepted to conversation
*/
public ChatWindow(Connection connection, Socket socket, boolean accepted) {
this.conversation = new Conversation();
this.view = new View(conversation);
this.controller = new Controller(view, conversation, connection,
accepted, socket);
ChatWindow.this.add(controller);
ChatWindow.this.pack();
ChatWindow.this.setVisible(true);
ChatWindow.this.setResizable(false);
ChatWindow.this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
try{
connection.disconnect(controller.name());
} catch (Exception ex) {
Logger.getLogger(ChatWindow.class.getName())
.log(Level.SEVERE, null, ex);
}
}
});
}
/**
*Constructor for multi conversation
* @param connection the instance of the TCP connection class
* @param accepted boolean, client accepted to conversation
*/
public ChatWindow(Connection connection, boolean accepted) {
this.conversation = new Conversation();
this.view = new View(conversation);
this.controller = new Controller(view, conversation,
connection, accepted);
ChatWindow.this.add(controller);
ChatWindow.this.pack();
ChatWindow.this.setVisible(true);
ChatWindow.this.setResizable(false);
ChatWindow.this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
try{
connection.disconnect(controller.name());
} catch (Exception ex) {
Logger.getLogger(ChatWindow.class.getName())
.log(Level.SEVERE, null, ex);
}
}
});
}
/**
*Get the conversation
* @return instance on Conversation
*/
public Conversation getConversation() {
return conversation;
}
/**
*Get controller
* @return the controller
*/
public Controller getController() {
return controller;
}
}