forked from biblelamp/JavaExercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwingClient.java
More file actions
65 lines (58 loc) · 1.96 KB
/
SwingClient.java
File metadata and controls
65 lines (58 loc) · 1.96 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
package lesson27;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class SwingClient extends JFrame implements ActionListener {
final String TITLE_OF_PROGRAM = "Client for network chat";
final int WINDOW_WIDTH = 350;
final int WINDOW_HEIGHT = 450;
final String BTN_ENTER = "Enter";
JTextArea dialogue; // area for dialog
JTextField message; // field for entering messages
public static void main(String[] args) {
new SwingClient();
}
public SwingClient() {
setTitle(TITLE_OF_PROGRAM);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setLocationRelativeTo(null); // to the center
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
}
});
// area for dialog
dialogue = new JTextArea();
dialogue.setLineWrap(true);
dialogue.setEditable(false);
JScrollPane scrollBar = new JScrollPane(dialogue);
// panel for command line and button
JPanel bp = new JPanel();
bp.setLayout(new BoxLayout(bp, BoxLayout.X_AXIS));
message = new JTextField();
message.addActionListener(this);
JButton enter = new JButton(BTN_ENTER);
enter.addActionListener(this);
// adding all elements to the window
bp.add(message);
bp.add(enter);
add(BorderLayout.CENTER, scrollBar);
add(BorderLayout.SOUTH, bp);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO
}
}