-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.java
More file actions
498 lines (437 loc) · 22.9 KB
/
Client.java
File metadata and controls
498 lines (437 loc) · 22.9 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package client.chat_infra;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JList;
import javax.swing.ListModel;
/**
*
* @author lider
*/
public class Client extends javax.swing.JFrame {
private int port = 3000;
private Socket socket;
private InetAddress serverAddr;
private byte[] server = {(byte)192, (byte) 168, 0, 101};
PrintWriter writer;
BufferedReader reader;
ArrayList<String> users = new ArrayList();
String nome;
/**
* Creates new form Client
*/
public Client() {
initComponents();
jLayeredPane2.setVisible(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLayeredPane1 = new javax.swing.JLayeredPane();
jDesktopPane1 = new javax.swing.JDesktopPane();
labelChat = new javax.swing.JLabel();
userName = new javax.swing.JTextField();
connectButton = new javax.swing.JButton();
exitButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
warningArea = new javax.swing.JTextArea();
jLayeredPane2 = new javax.swing.JLayeredPane();
jDesktopPane2 = new javax.swing.JDesktopPane();
sendText = new javax.swing.JTextField();
sendButton = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
chatArea = new javax.swing.JTextPane();
jPanel2 = new javax.swing.JPanel();
jScrollPane5 = new javax.swing.JScrollPane();
usersList = new javax.swing.JList<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Chat InfraCom");
setName("Chat InfraCom"); // NOI18N
setResizable(false);
jDesktopPane1.setBackground(new java.awt.Color(240, 240, 240));
labelChat.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
labelChat.setText("Chat InfraCom");
userName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
userName.setToolTipText("Nome");
userName.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nome", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
userName.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
userNameActionPerformed(evt);
}
});
connectButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
connectButton.setText("Conectar");
connectButton.setToolTipText("Conectar");
connectButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
connectButtonActionPerformed(evt);
}
});
exitButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
exitButton.setText("Sair");
exitButton.setToolTipText("Sair");
exitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitButtonActionPerformed(evt);
}
});
warningArea.setEditable(false);
warningArea.setBackground(new java.awt.Color(240, 240, 240));
warningArea.setColumns(1);
warningArea.setRows(1);
warningArea.setOpaque(false);
jScrollPane1.setViewportView(warningArea);
jDesktopPane1.setLayer(labelChat, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(userName, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(connectButton, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(exitButton, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
jDesktopPane1.setLayout(jDesktopPane1Layout);
jDesktopPane1Layout.setHorizontalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(connectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addGap(151, 151, 151)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(userName, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labelChat))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDesktopPane1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(129, 129, 129))
);
jDesktopPane1Layout.setVerticalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(labelChat)
.addGap(136, 136, 136)
.addComponent(userName, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(connectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(34, 34, 34))
);
jLayeredPane1.setLayer(jDesktopPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jLayeredPane1Layout = new javax.swing.GroupLayout(jLayeredPane1);
jLayeredPane1.setLayout(jLayeredPane1Layout);
jLayeredPane1Layout.setHorizontalGroup(
jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1)
);
jLayeredPane1Layout.setVerticalGroup(
jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1)
);
jDesktopPane2.setOpaque(false);
sendText.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendTextActionPerformed(evt);
}
});
sendButton.setText("Enviar");
sendButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendButtonActionPerformed(evt);
}
});
chatArea.setEditable(false);
jScrollPane2.setViewportView(chatArea);
jDesktopPane2.setLayer(sendText, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(sendButton, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jDesktopPane2Layout = new javax.swing.GroupLayout(jDesktopPane2);
jDesktopPane2.setLayout(jDesktopPane2Layout);
jDesktopPane2Layout.setHorizontalGroup(
jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addComponent(sendText, javax.swing.GroupLayout.DEFAULT_SIZE, 559, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(sendButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(6, 6, 6))
.addComponent(jScrollPane2)
);
jDesktopPane2Layout.setVerticalGroup(
jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sendText, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sendButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
usersList.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jScrollPane5.setViewportView(usersList);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE)
);
jLayeredPane2.setLayer(jDesktopPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLayeredPane2.setLayer(jPanel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jLayeredPane2Layout = new javax.swing.GroupLayout(jLayeredPane2);
jLayeredPane2.setLayout(jLayeredPane2Layout);
jLayeredPane2Layout.setHorizontalGroup(
jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane2)
.addGroup(jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane2Layout.createSequentialGroup()
.addContainerGap(202, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(309, Short.MAX_VALUE)))
);
jLayeredPane2Layout.setVerticalGroup(
jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane2)
.addGroup(jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane2Layout.createSequentialGroup()
.addContainerGap(81, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(149, Short.MAX_VALUE)))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane2, javax.swing.GroupLayout.Alignment.TRAILING))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane2, javax.swing.GroupLayout.Alignment.TRAILING))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendButtonActionPerformed
// TODO add your handling code here:
String msg = "";
if ((sendText.getText()).equals(msg)) {
sendText.setText("");
sendText.requestFocus();
} else {
try {
writer.println(nome + ":" + sendText.getText() + ":" + "Chat");
writer.flush(); // flushes the buffer
} catch (Exception ex) {
chatArea.setText(msg);
//chatArea.append("A mensagem não foi enviada. \n");
}
sendText.setText("");
sendText.requestFocus();
}
sendText.setText("");
sendText.requestFocus();
}//GEN-LAST:event_sendButtonActionPerformed
private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_exitButtonActionPerformed
private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectButtonActionPerformed
// TODO add your handling code here:
userName.setEditable(false);
nome = userName.getText();
try {
serverAddr = InetAddress.getByAddress(server);
socket = new Socket(serverAddr, port);
warningArea.setText("Conectando " + nome + "...");
jLayeredPane1.setVisible(false);
jLayeredPane2.setVisible(true);
jDesktopPane2.setVisible(true);
jPanel2.setVisible(false);
sendText.requestFocus();
InputStreamReader streamReader = new InputStreamReader(socket.getInputStream());
reader = new BufferedReader(streamReader);
writer = new PrintWriter(socket.getOutputStream());
System.out.println(nome);
writer.println(nome + ":Conectou.:Connect");
writer.flush();
} catch (IOException ex) {
jDesktopPane2.setVisible(false);
jDesktopPane1.setVisible(true);
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
warningArea.setText("Falha ao se conectar!");
}
ListenThread();
}//GEN-LAST:event_connectButtonActionPerformed
private void sendTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendTextActionPerformed
// TODO add your handling code here:
String msg;
sendText.setEditable(false);
msg = sendText.getText();
sendMessage(msg);
}//GEN-LAST:event_sendTextActionPerformed
private void userNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userNameActionPerformed
// TODO add your handling code here:
userName.setEditable(false);
nome = userName.getText();
try {
serverAddr = InetAddress.getLocalHost();
socket = new Socket("localhost", port);
warningArea.setText("Conectando " + nome + "...");
jLayeredPane1.setVisible(false);
jLayeredPane2.setVisible(true);
jDesktopPane2.setVisible(true);
sendText.requestFocus();
InputStreamReader streamReader = new InputStreamReader(socket.getInputStream());
reader = new BufferedReader(streamReader);
writer = new PrintWriter(socket.getOutputStream());
System.out.println(nome);
writer.println(nome + ":Conectou.:Connect");
writer.flush();
} catch (IOException ex) {
jDesktopPane2.setVisible(false);
jDesktopPane1.setVisible(true);
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
warningArea.setText("Falha ao se conectar!");
}
ListenThread();
}//GEN-LAST:event_userNameActionPerformed
/**/
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Client().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextPane chatArea;
private javax.swing.JButton connectButton;
private javax.swing.JButton exitButton;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JDesktopPane jDesktopPane2;
private javax.swing.JLayeredPane jLayeredPane1;
private javax.swing.JLayeredPane jLayeredPane2;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JLabel labelChat;
private javax.swing.JButton sendButton;
private javax.swing.JTextField sendText;
private javax.swing.JTextField userName;
private javax.swing.JList<String> usersList;
private javax.swing.JTextArea warningArea;
// End of variables declaration//GEN-END:variables
private void ListenThread() {
Thread incomingReader = new Thread(new IncomingReader());
incomingReader.start();
}
private void sendMessage(String msg) {
String nothing = "";
if ((sendText.getText()).equals(nothing)) {
sendText.setText("");
sendText.requestFocus();
} else {
try {
writer.println(nome + ":" + sendText.getText() + ":" + "Chat");
writer.flush(); // flushes the buffer
} catch (Exception ex) {
System.out.println("A mensagem não foi enviada. \n");
}
sendText.setText("");
sendText.requestFocus();
sendText.setEditable(true);
}
}
public class IncomingReader implements Runnable {
@Override
public void run() {
String[] data;
String stream, done="Done", connect="Connect", disconnect="Disconnect", chat="Chat", userList = "userList";
try {
while ((stream = reader.readLine()) != null) {
data = stream.split(":");
if (data[2].equals(chat)) {
if (data[0].equalsIgnoreCase(nome)) {
chatArea.setText(chatArea.getText() + "[Você] " + data[1] + "\n");
chatArea.setCaretPosition(chatArea.getDocument().getLength());
} else {
chatArea.setText(chatArea.getText() + "[" + data[0] + "] " + data[1] + "\n");
chatArea.setCaretPosition(chatArea.getDocument().getLength());
}
} else if (data[2].equals(connect)) {
chatArea.removeAll();
userAdd(data[0]);
} else if (data[2].equals(done)) {
writeUsers();
users.clear();
} else if (data[2].equals(userList)) {
System.out.println(stream);
userAdd(data[1]);
}
}
} catch (Exception ex) {
writeUsers();
users.clear();
}
}
private void userAdd(String data) {
users.add(data);
}
private void writeUsers() {
String[] tempList = new String [users.size()];
users.toArray(tempList);
for (String token:tempList) {
}
}
}
}