-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevent.java
More file actions
41 lines (41 loc) · 1.52 KB
/
event.java
File metadata and controls
41 lines (41 loc) · 1.52 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
import ru.geekbrains.chat.network.TCPConnection;
import ru.geekbrains.chat.network.TCPConnectionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
public class ClientWindow extends JFrame implements ActionListener, TCPConnectionListener {
private static final String IP_ADDR = "127.0.0.1";
private static final int PORT = 8080;
private static final int width = 600;
private static final int height = 400;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new ClientWindow();
}
});
}
private final JTextArea log = new JTextArea();
private final JTextField fieldNickname = new JTextField("Alex");
private final JTextField fieldInput = new JTextField();
private TCPConnection connection;
private ClientWindow() {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(width, height);
setLocationRelativeTo(null);
setAlwaysOnTop(true);
log.setEditable(false);
log.setLineWrap(true);
add(log, BorderLayout.CENTER);
fieldInput.addActionListener(this);
add(fieldInput, BorderLayout.SOUTH);
add(fieldNickname, BorderLayout.NORTH);
setVisible(true);
try {
connection = new TCPConnection(this, IP_ADDR, PORT);
} catch (IOException e) {
printMag("Connection exception: " + e);
}
}
}