-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupWindow.java
More file actions
147 lines (120 loc) · 3.42 KB
/
GroupWindow.java
File metadata and controls
147 lines (120 loc) · 3.42 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package chatapp;
import java.awt.EventQueue;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class GroupWindow extends JFrame {
private JPanel contentPane;
String group_name;
JTextArea textArea;
private JTextField textField;
private JTextField textField_1;
List list = new List();
Peer pee;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
// Group frame = new Group();
// frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @param pe
*/
public void update_groups()
{
list.removeAll();
for(int i=0;i<pee.group_list.size();i++)
{
list.add(pee.group_list.get(i).name);
}
}
public GroupWindow(Peer pe) {
this.pee=pe;
pe.group=this;
pee.update_me();
update_groups();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(28, 204, 261, 20);
contentPane.add(textField);
textField.setColumns(10);
JButton btnSend = new JButton("Send");
btnSend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.setText(textArea.getText().trim()+"\n"+"me"+":"+textField.getText());
pee.send_group_message(group_name, textField.getText());
textField.setText("".trim());
}
});
btnSend.setBounds(200, 227, 89, 23);
contentPane.add(btnSend);
list = new List();
list.setBounds(314, 10, 110, 172);
contentPane.add(list);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(28, 82, 261, 115);
contentPane.add(scrollPane);
textArea = new JTextArea();
scrollPane.setViewportView(textArea);
textArea.setEditable(false);
JButton btnCreateGroup = new JButton("Create Group");
btnCreateGroup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!textField_1.getText().equals(""))
{
pee.creategroup(textField_1.getText());
pee.update_me();
group_name=textField_1.getText();
}
}
});
btnCreateGroup.setBounds(10, 11, 110, 23);
contentPane.add(btnCreateGroup);
textField_1 = new JTextField();
textField_1.setBounds(130, 12, 86, 20);
contentPane.add(textField_1);
textField_1.setColumns(10);
JButton btnJoin = new JButton("Join");
btnJoin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
pee.joingroup(list.getSelectedItem());
group_name=list.getSelectedItem();
}
});
btnJoin.setBounds(324, 188, 89, 23);
contentPane.add(btnJoin);
JButton btnR = new JButton("R");
btnR.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
pee.update_me();
}
});
btnR.setBounds(385, 227, 39, 23);
contentPane.add(btnR);
}
public void recived_group_message(broadcast_messsage_send group_message) {
textArea.setText(textArea.getText().trim()+"\n"+group_message.sender_name+":"+group_message.data);
}
}