-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewJDialog.java
634 lines (578 loc) · 30 KB
/
NewJDialog.java
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
import javax.swing.JOptionPane;
import java.util.*;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JList;
public class NewJDialog extends javax.swing.JDialog implements Runnable {
static Map<String, String> names= new HashMap<String, String>();
static Map<String, String> ips = new HashMap<String, String>();
static Map<String, String> messages = new HashMap<String, String>();
static DefaultListModel model = new DefaultListModel();
//NewJDialog dia = this;
/**
* Creates new form NewJDialog
*/
//HashMap map;
public NewJDialog(){
//initComponents();
}
public NewJDialog(java.awt.Frame parent, boolean modal) throws IOException {
super(parent, modal);
initComponents();
jPanel3.setVisible(false);
String arg[] = new String[0];
new BroadcastName().send(jLabel4.getText());
//JOptionPane.showMessageDialog(null,"Started");
//int port = args.length == 0 ? 4000 : Integer.parseInt(args[0]);
// Thread tt = new Thread(new GetAck());
// tt.start();
//
//GetAck.init(this);
GetAck.run(4001);
//Reciever.init(this);
//udpBaseServer_2.init(this);
GroupChat.init(this);
ftp_client.init(this);
//MultiReceive.init(this);
//messages.put("Anurag", "Hello");
Thread t1 = new Thread(new NewJDialog());
t1.start();
Thread t2 = new Thread(new udpBaseServer_2());
t2.start();
Thread t3 = new Thread(new GroupChat());
t3.start();
Thread t4 = new Thread(new ftp_client());
t4.start();
// Thread t3 = new Thread(new udpBaseClient_2());
// t3.start();
}
public static String getMyName() {
return jLabel4.getText();
}
public boolean checktype(String str)
{
System.out.println("in checktype fn " + str);
String ip = /*dia.*/names.get(str);
System.out.println("ip="+ip);
if(ip == null) return false;
String[] st= ip.split("\\.");
System.out.println("st= "+st[0]);
int address=Integer.parseInt(st[0]);
System.out.println("address"+address);
// Integer[] address;
// address[0]=Integer.parseInt(ip1[0]);
// address[1]=Integer.parseInt(ip1[1]);
// address[2]=Integer.parseInt(ip1[2]);
// address[3]=Integer.parseInt(ip1[3]);
System.out.println("exiting fuction");
if(address<=239 && address>=224)
{
return false;
}
else return true;
}
public static void additem(DefaultListModel mod, NewJDialog dia, String name, String ip) {
if(name.equals(/*dia.*/jLabel4.getText())) {
return;
}
if(/*dia.*/names.containsKey(name)){
System.out.println("pehle se hai");
/*dia.*/names.put(name, ip);
/*dia.*/ips.remove(/*dia.*/names.get(name));
/*dia.*/ips.put(ip, name);
}
else {
System.out.println("naya hai");
name=name.trim();
ip=ip.trim();
System.out.println("ip:" + ip + " name:"+name);
model.addElement(name);
/*dia.*/names.put(name, ip);
/*dia.*/ips.put(ip, name);
/*dia.*/messages.put(name, "");
}
}
public void receivetext(DefaultListModel mod, NewJDialog dia, String name, String ip) {
//jTextArea1.append(sentence);
//JOptionPane.showMessageDialog(null,"Hi receive called");
if(/*dia.*/names.containsKey(ip)) {
//dia.removeElementAt(dia.);
}
System.out.println("receiveText " + name + " " + ip);
name.trim();
/*dia.*/names.put(name, ip);
/*dia.*/ips.put(ip, name);
/*dia.*/jList1.setModel(model);
}
public static void receive(String data, String ip, NewJDialog dia) {
System.out.println("receive me hu ");
System.out.println(data + " " + ip + " " + /*dia.*/ips.get(ip));
if(/*dia.*/ips.get(ip) == null) return;
String name = /*dia.*/ips.get(ip);
if(/*dia.*/messages.get(name)==null){
/*dia.*/messages.put(name, data);
}
else {
String oldchat = /*dia.*/messages.get(name);
/*dia.*/messages.put(name, oldchat + "\n" + data);
}
///*dia.*/messages.put(name, dia.messages.get(name)==null?"":dia.messages.get(name) + "\n" + data);
if(/*dia.*/!jList1.isSelectionEmpty() && jList1.getSelectedValue().trim().equals(name.trim())) {
//if(checktype(name)) {
System.out.println("receive here data = " + data);
/*dia.*/jTextArea1.append("\n" + data);
//}
}
}
/*public void receive()
{
JOptionPane.showMessageDialog(null,"Hi its Qazi");
//jTextArea1.append("\n"+"hehe\n");
}*/
public void run() {
//JOptionPane.showMessageDialog(null,"Hi its");
try{
int port=4000;
new Reciever().run(port);
}
catch(Exception e){
System.out.println(e);
}
}
/**
* 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() {
jLabel4 = new javax.swing.JLabel();
jLayeredPane1 = new javax.swing.JLayeredPane();
jPanel1 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList<>();
jScrollPane5 = new javax.swing.JScrollPane();
jButton2 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jScrollPane3 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
SendFileBtn = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jScrollPane4 = new javax.swing.JScrollPane();
jList2 = new javax.swing.JList<>();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setMaximumSize(new java.awt.Dimension(1920, 1080));
setMinimumSize(new java.awt.Dimension(800, 600));
setPreferredSize(new java.awt.Dimension(800, 600));
jLabel4.setFont(new java.awt.Font("Noto Sans", 0, 24)); // NOI18N
jLabel4.setText("Qazi");
jList1.setBackground(new java.awt.Color(219, 240, 251));
jList1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 199, 255), 1, true));
jList1.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N
jList1.setModel(new DefaultListModel());
jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jList1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jList1MouseClicked(evt);
}
});
jScrollPane2.setViewportView(jList1);
jButton2.setText("New Group");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel2.setText("Users & Groups");
jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel2MouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(213, 213, 213)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addContainerGap(17, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addGap(17, 17, 17))
);
jLabel3.setText("Chat");
jTextArea1.setEditable(false);
jTextArea1.setBackground(new java.awt.Color(196, 246, 196));
jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("Noto Sans", 0, 14)); // NOI18N
jTextArea1.setRows(5);
jTextArea1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(1, 168, 2), 1, true));
jScrollPane1.setViewportView(jTextArea1);
jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane3.setAutoscrolls(true);
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane3.setViewportView(jTextArea2);
jButton1.setText("Send");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
SendFileBtn.setText("Send File");
SendFileBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SendFileBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(44, 44, 44)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane1)
.addContainerGap())
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SendFileBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31))))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1)
.addGap(19, 19, 19)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(SendFileBtn))))
);
jLabel1.setText("Group Name");
jList2.setModel(new DefaultListModel());
jScrollPane4.setViewportView(jList2);
jButton3.setText("Create");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("Cancel");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(93, 93, 93)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))))))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4)
.addContainerGap())
.addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)))
);
jLayeredPane1.setLayer(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLayeredPane1.setLayer(jPanel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLayeredPane1.setLayer(jPanel3, 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)
.addGroup(jLayeredPane1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(48, 48, 48))
.addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jLayeredPane1Layout.createSequentialGroup()
.addGap(304, 304, 304)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(61, Short.MAX_VALUE)))
);
jLayeredPane1Layout.setVerticalGroup(
jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jLayeredPane1Layout.createSequentialGroup()
.addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jLayeredPane1Layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(39, 39, 39))
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
.addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jLayeredPane1Layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(111, 111, 111)))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLayeredPane1)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(16, 16, 16)
.addComponent(jLayeredPane1)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
// TODO add your handling code here:
String name=jList1.getSelectedValue();
jTextArea1.setText(messages.get(name));
}//GEN-LAST:event_jList1MouseClicked
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
//DefaultListModel modd = new DefaultListModel();
GroupChat.multimod
=(DefaultListModel) jList1.getModel();
//jList2.setModel(new DefaultListModel());
jList2.setModel(GroupChat.multimod);
jPanel3.setVisible(true);
jPanel2.setVisible(false);
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
String multicastaddress="239.0.0.1";
byte[] groupid = multicastaddress.getBytes();
String name=jTextField1.getText();
groupid=(multicastaddress+"+"+name).getBytes();
List<String> values=jList2.getSelectedValuesList();
for(int i=0;i<values.size();i++)
{
String ip=names.get(values.get(i));
try {
DatagramSocket socket=new DatagramSocket();
DatagramPacket sendData;
sendData = new DatagramPacket(groupid,groupid.length,InetAddress.getByName(ip),7001);
System.out.println("Sending datapacket ");
socket.send(sendData);
System.out.println("datapacket sent");
new GroupChat().join(multicastaddress, 1666, name);
} catch (UnknownHostException | SocketException ex) {
Logger.getLogger(NewJDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(NewJDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}
//((DefaultListModel)jList2.getModel()).removeAllElements();
//GroupChat.multimod.removeAllElements();
jTextField1.setText("");
jPanel3.setVisible(false);
jPanel2.setVisible(true);
}//GEN-LAST:event_jButton3ActionPerformed
private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jLabel2MouseClicked
private void SendFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SendFileBtnActionPerformed
// TODO add your handling code here:
// TODO add your handling code here:
if(jList1.isSelectionEmpty()) return;
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("choosertitle");
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
//System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
//System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
String path = chooser.getSelectedFile().toString();
String name = jList1.getSelectedValue();
String ip = names.get(name);
try {
// Sending file
ftp_server.send(path, ip);
} catch (IOException ex) {
Logger.getLogger(NewJDialog.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
System.out.println("No Selection ");
}
}//GEN-LAST:event_SendFileBtnActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
try{
String data=jLabel4.getText()+": "+jTextArea2.getText();
String name=jList1.getSelectedValue();
name.trim();
jTextArea1.append("\n"+ data);
messages.put(name, messages.get(name)==null?"":messages.get(name) + "\n" + data);
jTextArea2.setText("");
System.out.println("button press " + data + " " + name + " " + names.get(name));
System.out.println(Arrays.asList(names));
System.out.println("Ho gya");
System.out.println("unicast="+checktype(name));
if(checktype(name))
udpBaseClient_2.sendData(data, names.get(name));
else
{
GroupChat.sendData(data, names.get(name), 1666);
}
}
catch(Exception e){}
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
jPanel3.setVisible(false);
jPanel2.setVisible(true);
}//GEN-LAST:event_jButton4ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) throws IOException{
/* 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 ("GTK+".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run(){
try{
NewJDialog dialog = new NewJDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
catch(Exception e){
System.out.println(e);
}
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton SendFileBtn;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private static javax.swing.JLabel jLabel4;
private javax.swing.JLayeredPane jLayeredPane1;
private static javax.swing.JList<String> jList1;
private javax.swing.JList<String> jList2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private static javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}