-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkingMesseger.java
More file actions
119 lines (103 loc) · 2.57 KB
/
Copy pathWorkingMesseger.java
File metadata and controls
119 lines (103 loc) · 2.57 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
package joshua;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
public class WorkingMesseger extends JFrame{
Socket s = new Socket();
JButton connect;
DataInputStream input;
DataOutputStream output;
InetAddress inet;
private String helper;
private int one = 1;
JTextField textfield = new JTextField();
JButton send = new JButton();
JTextArea panel = new JTextArea();
public WorkingMesseger(){
super("Messeger");
if(one == 1){
connect = new JButton("Connect");
textfield = new JTextField(30);
panel = new JTextArea();
send = new JButton("Send");
setLayout(null);
panel.setBounds(60,60,200,100);
connect.setBounds(50,10, 200, 40);
textfield.setBounds(60,260, 200, 40);
send.setBounds(60, 180, 200, 40);
add(send);
add(connect);
add(textfield);
setLayout(null);
add(panel);
connect.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
remove(connect);
add(panel);
add(send);
try {
make();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Thread thread2 = new Thread(){
public void run(){
while(true){
try {
setPanel(input.readUTF());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
thread2.start();
}
}
);
send.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
helper = textfield.getText();
output.writeUTF(helper);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
);
one = 2;
}
else{
}
}
public void setPanel(String y){
String x;
x = panel.getText();
panel.setText(x + "\n" + y);
}
public void make() throws IOException{
inet = InetAddress.getByName("127.0.0.1");
s = new Socket(inet, 25543);
input = new DataInputStream(s.getInputStream());
output = new DataOutputStream(s.getOutputStream());
}
}