-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatWindow.java
More file actions
67 lines (53 loc) · 1.69 KB
/
ChatWindow.java
File metadata and controls
67 lines (53 loc) · 1.69 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
package src2;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ChatWindow {
JFrame mainFrame;
JTextField textBox;
JTextArea msgArea;
JPanel controlPanel;
JButton sendButton;
String usernames;
ChatWindow(String _usernames) {
mainFrame = new JFrame("");
textBox = new JTextField();
msgArea = new JTextArea();
controlPanel = new JPanel();
sendButton = new JButton("Send");
sendButton.setPreferredSize(new Dimension(40, 60));
usernames = _usernames;
addComponents();
}
public void addComponents() {
mainFrame.setLayout(new GridLayout(0,1));
controlPanel.setLayout(new BorderLayout());
mainFrame.add(msgArea);
msgArea.append("STARTING CHAT WITH " + usernames);
mainFrame.add(textBox);
mainFrame.add(controlPanel);
controlPanel.add(sendButton, BorderLayout.SOUTH);
mainFrame.setVisible(true);
mainFrame.setSize(600, 600);
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public JButton getButton() {
return sendButton;
}
public String getText() {
return textBox.getText();
}
public void addTextFromThisUser(String string) {
msgArea.append("\n" + string);
textBox.setText("");
textBox.requestFocus();
}
public void addTextFromOtherUser(String string) {
msgArea.append("\n" + string);
}
}