-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatRoomSelectPanel.java
More file actions
96 lines (72 loc) · 2.54 KB
/
ChatRoomSelectPanel.java
File metadata and controls
96 lines (72 loc) · 2.54 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ChatRoomSelectPanel extends JPanel {
JTextField _chatRoomName;
JButton _connectButton;
ChatClient _client;
public ChatRoomSelectPanel(ChatClient client){
_client = client;
try {
componentInit();
}catch (Exception e){
}
}
private void componentInit() {
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridBag);
addLabel(gridBag,"Connection is successful.\nPlease enter the name of the Chatroom that you want to join",SwingConstants.CENTER,1,0,2,1);
addLabel(gridBag,"Chatroom name: ",SwingConstants.CENTER,1,1,1,1);
_chatRoomName = new JTextField();
addField(gridBag, _chatRoomName, 2, 1, 1, 1);
_connectButton = new JButton("Connect");
c.gridx = 1;
c.gridy = 5;
c.gridwidth = 2;
gridBag.setConstraints(_connectButton, c);
add(_connectButton);
_connectButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
joinChatRoom();
_client.enterChatRoom();
//Connect to chatroom islemi yapilacak.
}
});
}
private void joinChatRoom(){
String chatRoomName = _chatRoomName.getText();
_client.joinChatRoom(chatRoomName);
}
JLabel addLabel(GridBagLayout gridBag, String labelStr, int align,
int x, int y, int width, int height) {
GridBagConstraints c = new GridBagConstraints();
JLabel label = new JLabel(labelStr);
if (align == SwingConstants.LEFT) {
c.anchor = GridBagConstraints.WEST;
} else {
c.insets = new Insets(10, 0, 10, 0);
}
c.gridx = x;
c.gridy = y;
c.gridwidth = width;
c.gridheight = height;
gridBag.setConstraints(label, c);
add(label);
return label;
}
void addField(GridBagLayout gridBag, JTextField field, int x, int y,
int width, int height) {
GridBagConstraints c = new GridBagConstraints();
field.setPreferredSize(new Dimension(96,
field.getMinimumSize().height));
c.gridx = x;
c.gridy = y;
c.gridwidth = width;
c.gridheight = height;
gridBag.setConstraints(field, c);
add(field);
}
}