-
Notifications
You must be signed in to change notification settings - Fork 0
/
c11.java
451 lines (391 loc) · 13.1 KB
/
c11.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
package FDBS1;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.StringTokenizer;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class c11 {
static JFrame frame;
private JTextField tf;
static Socket s;
static DataInputStream din;
static DataOutputStream dout;
static FileOutputStream fos;
private JScrollPane scrollPane;
private JScrollPane scrollPane_1;
static JTextArea ta3;
static String line1,name,result;
static int mm;
static JTextArea ta;
static JTextField tf1;
static JTextArea ta2;
/**
* Launch the application.
* @throws IOException
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException, IOException {
s=new Socket("127.0.0.1",9998);
din = new DataInputStream(s.getInputStream());
dout= new DataOutputStream(s.getOutputStream());
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login window = new Login();
window.frame.setVisible(true);
c11 window1 = new c11();
window1.frame.setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
String line=" ";int i=0;
do {
result=din.readUTF();
if(result.equals("us"));
{
Login.rr.setText("Incorrect");
Timer t = new Timer(4000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Login.rr.setText(null);
}
});
t.setRepeats(false);
t.start();
Login.i.setText(null);
Login.p.setText(null);
}}while(!result.equals("s"));
frame.setVisible(true);
Login.frame.dispose();
line1=din.readUTF();
name=din.readUTF();
frame.setTitle(name);
while(!line.equals("exit"))
{
line=din.readUTF();
if(line.charAt(0)=='*')
{String p,p1;
p=din.readUTF();
if(p.equals("student")) {
Object[][] rowData = {};
Object[] columnNames = { "ID", "Name", "Email_ID","Phone_No." };
DefaultTableModel listTableModel;
listTableModel = new DefaultTableModel(rowData, columnNames);
while(true)
{
p1=din.readUTF();
if(p1.equals("o#o"))break;
StringTokenizer st = new StringTokenizer(p1, "#");
String m = st.nextToken();
String r = st.nextToken();
String r1 = st.nextToken();
String r2 = st.nextToken();
listTableModel.addRow(new Object[] {m,r,r1,r2});
}
Database.table = new JTable(listTableModel);
Database.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Database.table.setCellEditor(null);
Database.scrollPane.setViewportView(Database.table);
}
else if(p.equals("internships"))
{
Object[][] rowData = {};
Object[] columnNames = { "ID", "Company", "Pay","Project" };
DefaultTableModel listTableModel;
listTableModel = new DefaultTableModel(rowData, columnNames);
while(true)
{
p1=din.readUTF();
if(p1.equals("o#o"))break;
StringTokenizer st = new StringTokenizer(p1, "#");
String m = st.nextToken();
String r = st.nextToken();
String r1 = st.nextToken();
String r2 = st.nextToken();
listTableModel.addRow(new Object[] {m,r,r1,r2});
}
Database.table = new JTable(listTableModel);
Database.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Database.table.setCellEditor(null);
Database.scrollPane.setViewportView(Database.table);
}
else if(p.equals("marks")) {
Object[][] rowData = {};
Object[] columnNames = { "ID", "MST", "ESE","TA","Total","Grades" };
DefaultTableModel listTableModel;
listTableModel = new DefaultTableModel(rowData, columnNames);
while(true)
{
p1=din.readUTF();
if(p1.equals("o#o"))break;
StringTokenizer st = new StringTokenizer(p1, "#");
String m = st.nextToken();
String r = st.nextToken();
String r1 = st.nextToken();
String r2 = st.nextToken();
String r3 = st.nextToken();
String r4 = st.nextToken();
listTableModel.addRow(new Object[] {m,r,r1,r2,r3,r4});
}
Database.table = new JTable(listTableModel);
Database.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Database.table.setCellEditor(null);
Database.scrollPane.setViewportView(Database.table);
}
else if(p.equals("grade")) {
Object[][] rowData = {};
Object[] columnNames = { "ID","Grades" };
DefaultTableModel listTableModel;
listTableModel = new DefaultTableModel(rowData, columnNames);
while(true)
{
p1=din.readUTF();
if(p1.equals("o#o"))break;
StringTokenizer st = new StringTokenizer(p1, "#");
String m = st.nextToken();
String r = st.nextToken();
listTableModel.addRow(new Object[] {m,r});
}
Database.table = new JTable(listTableModel);
Database.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Database.table.setCellEditor(null);
Database.scrollPane.setViewportView(Database.table);
}
else if(p.equals("info")) {
Object[][] rowData = {};
Object[] columnNames = { "ID","Name","Email_ID","Phone_No","MST","ESE","TA","Total","Grades","Company","Pay","Project"};
DefaultTableModel listTableModel;
listTableModel = new DefaultTableModel(rowData, columnNames);
while(true)
{
p1=din.readUTF();
if(p1.equals("o#o"))break;
StringTokenizer st = new StringTokenizer(p1, "#");
String m = st.nextToken();
String r = st.nextToken();
String r1 = st.nextToken();
String r2= st.nextToken();
String r3= st.nextToken();
String r4= st.nextToken();
String r5 = st.nextToken();
String r6 = st.nextToken();
String r7 = st.nextToken();
String r8 = st.nextToken();
String r9 = st.nextToken();
String r10 = st.nextToken();
listTableModel.addRow(new Object[] {m,r,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10});
}
Database.table = new JTable(listTableModel);
Database.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Database.table.setCellEditor(null);
Database.scrollPane.setViewportView(Database.table);
}
else {}
}
else if(line.charAt(0)=='&')
{
String h=din.readUTF();
StringTokenizer st = new StringTokenizer(h, "#");
String m = st.nextToken();
String r = st.nextToken();
String r1 = st.nextToken();
if(r1.equals("1"))
{ ta.setText(ta.getText().trim()+"\n"+m+" send you "+r);}
else
{
PC1.textArea.setText(PC1.textArea.getText().trim()+"\n"+m+" send you "+r);
}
long bytesRead;byte b[]=new byte [1024];String j;
FileOutputStream fos=new FileOutputStream(new File(name+i+r),true);
do
{
bytesRead = din.read(b, 0, b.length);
fos.write(b,0,b.length);
}while(!(bytesRead<1024));
fos.close();i++;
}
else if(line.charAt(1)=='@')
{
StringTokenizer st = new StringTokenizer(line, "@");
String MsgToSend = st.nextToken();
String recipient = st.nextToken();
System.out.println(recipient);
ta3.setText(ta3.getText().trim()+"\n"+recipient);
}
else if(line.equals("5#"))
{
String z=din.readUTF();
PC1.textArea.setText(PC1.textArea.getText().trim()+"\n"+z);
}
else if(line.equals("55@#"))
{
String z=din.readUTF();
ta2.setText(ta2.getText().trim()+"\n"+z);
}
else {
ta.setText(ta.getText().trim()+"\n"+line);
}
}
}
/**
* Create the application.
*/
public c11() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 579, 452);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
scrollPane = new JScrollPane();
scrollPane.setBounds(10, 42, 345, 299);
frame.getContentPane().add(scrollPane);
ta = new JTextArea();
scrollPane.setViewportView(ta);
scrollPane_1 = new JScrollPane();
scrollPane_1.setBounds(365, 42, 189, 101);
frame.getContentPane().add(scrollPane_1);
ta3 = new JTextArea();
scrollPane_1.setViewportView(ta3);
JButton logout = new JButton("Logout");
logout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String line="logout";
try {
dout.writeUTF(line);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
dout.close();
din.close();
s.close();
System.out.println("client closed");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
logout.setBounds(10, 11, 102, 26);
frame.getContentPane().add(logout);
JButton btnNewButton_1 = new JButton("Active Users");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ta3.setText(null);
String line="$$$$";
try {
dout.writeUTF(line);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
btnNewButton_1.setBounds(122, 11, 129, 26);
frame.getContentPane().add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("Database");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Database window = new Database();
window.frame.setVisible(true);
}
});
btnNewButton_2.setBounds(264, 12, 110, 24);
frame.getContentPane().add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("PC");
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
PCname window = new PCname();
window.frame.setVisible(true);
}
});
btnNewButton_3.setBounds(384, 12, 91, 24);
frame.getContentPane().add(btnNewButton_3);
tf = new JTextField();
tf.setBounds(10, 351, 345, 54);
frame.getContentPane().add(tf);
tf.setColumns(10);
JButton btnNewButton_4 = new JButton("Share");
btnNewButton_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
mm=0;
file window = new file();
window.frame.setVisible(true);
}
});
btnNewButton_4.setBounds(457, 384, 85, 21);
frame.getContentPane().add(btnNewButton_4);
JButton btnNewButton_5 = new JButton("Send");
btnNewButton_5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String line=" ";
line=tf.getText().trim();
try {
dout.writeUTF(line);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tf.setText(null);
}
});
btnNewButton_5.setBounds(365, 384, 85, 21);
frame.getContentPane().add(btnNewButton_5);
JScrollPane scrollPane_2 = new JScrollPane();
scrollPane_2.setBounds(365, 266, 189, 75);
frame.getContentPane().add(scrollPane_2);
tf1 = new JTextField();
scrollPane_2.setViewportView(tf1);
tf1.setColumns(10);
JScrollPane scrollPane_3 = new JScrollPane();
scrollPane_3.setBounds(365, 151, 189, 82);
frame.getContentPane().add(scrollPane_3);
ta2 = new JTextArea();
scrollPane_3.setViewportView(ta2);
JLabel lblNewLabel = new JLabel("Annoucement:");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(393, 243, 117, 21);
frame.getContentPane().add(lblNewLabel);
JButton btnPost = new JButton("Post");
btnPost.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String line123=" ";
line123=tf1.getText().trim();
try {
dout.writeUTF("55@#");
dout.writeUTF(line123);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tf1.setText(null);
}
});
btnPost.setBounds(412, 353, 85, 21);
frame.getContentPane().add(btnPost);
}
}