-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectClient.java
50 lines (47 loc) · 1.13 KB
/
ProjectClient.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
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class ProjectClient extends JApplet implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public JButton sendText;
public JLabel label;
public JTextField textField;
public DataOutputStream toServer;
public void init(){
JPanel panel = new JPanel();
JFrame frame = new JFrame();
frame.setSize(400,400);
sendText = new JButton();
sendText.setText("Send");
textField = new JTextField(20);
textField.setSize(100, 10);
panel.add(sendText);
panel.add(textField, BorderLayout.NORTH);
frame.add(panel);
frame.setVisible(true);
try {
Socket socket = new Socket("localhost", 8000);
toServer = new DataOutputStream(socket.getOutputStream());
sendText.addActionListener(this);
}
catch (IOException ex){
System.err.println(ex);
}
}
public void actionPerformed(ActionEvent e) {
if (textField.getText() != null){
try {
toServer.writeUTF(textField.getText());
textField.setText("");
}
catch (IOException e1){
e1.printStackTrace();
}
}
}
}