-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser1.java
More file actions
76 lines (62 loc) · 1.83 KB
/
user1.java
File metadata and controls
76 lines (62 loc) · 1.83 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
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.DataOutputStream;
import java.io.DataInputStream;
public class user1 extends Frame implements Runnable,ActionListener{
TextField tf;
TextArea ta;
Button send;
Socket s;
DataInputStream di;
DataOutputStream dd;
Thread c;
user1(){
tf=new TextField();
ta=new TextArea();
send=new Button("send");
send.addActionListener(this);
try{
s = new Socket("localhost", 12000);
di=new DataInputStream(s.getInputStream());
dd=new DataOutputStream(s.getOutputStream());
}
catch(Exception e){
}
add(tf);
add(ta);
add(send);
c=new Thread(this);
c.setDaemon(true);
c.start();
setSize(500,500);
setTitle("user1");
setLayout(new FlowLayout());
setVisible(true);
}
public void actionPerformed(ActionEvent e){
String msg=tf.getText();
ta.append("user1:"+msg+"\n");
tf.setText("");
try{
dd.writeUTF(msg);
dd.flush();
}
catch(Exception ex){
}
}
public static void main(String[] args){
new user1();
}
public void run(){
while(true){
try{
String msg= di.readUTF();
ta.append("user2:"+msg+"\n");
}
catch(Exception e){
}
}
}
}