-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.java
More file actions
168 lines (134 loc) · 6.38 KB
/
Interface.java
File metadata and controls
168 lines (134 loc) · 6.38 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
public class Interface extends JFrame {
public static boolean clientFlag = false;
public static JLabel ipLabel;
public JLabel label, label1;
public static JTextField textField;
public static JTextArea textArea;
public static JButton button;
public JScrollPane scrollPane;
public static JTextField ipField, portField;
public static JButton ipButton;
public static JButton historyButton;
public static JLabel status, connectionStatus, connectionStatus1, yourIp;
public static Highlighter hilit;
public static Highlighter.HighlightPainter painter;
public static Client cli;
public static Server serv;
public static ActionListener connectListener, textListener;
public Interface() {
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
status = new JLabel("Connect to somebody");
hilit = new DefaultHighlighter();
painter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY);
label = new JLabel("Connect to ip");
label1 = new JLabel("and port");
connectionStatus = new JLabel("");
connectionStatus1 = new JLabel("");
connectionStatus.setFont(new Font("Sans Serif", Font.ITALIC, 11));
connectionStatus1.setFont(new Font("Sans Serif", Font.ITALIC, 11));
ipLabel = new JLabel("Disconnected");
ipLabel.setForeground(Color.red);
textField = new JTextField(5);
textField.addActionListener(textListener = new TextAction());
ipField = new JTextField(5);
portField = new JTextField(5);
ipButton = new JButton("Connect");
ipButton.addActionListener(connectListener = new ConnectionAction());
historyButton = new JButton("History");
historyButton.addActionListener(new historyButAction());
textArea = new JTextArea(20, 30);
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setHighlighter(hilit);
button = new JButton("Send");
button.addActionListener(textListener);
serv = new Server(4000); //server
serv.start();
yourIp = new JLabel("");
yourIp.setFont(new Font("Sans Serif", Font.ITALIC, 12));
this.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent event) {
TextFile.update("===============End of session==============");
if (clientFlag) {
cli.getMessage("//disable");
}
System.exit(0);
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
});
scrollPane = new JScrollPane(textArea);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(scrollPane))
.addGroup(layout.createSequentialGroup()
.addComponent(textField)
.addComponent(button))
.addComponent(status)
.addComponent(yourIp))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(label)
.addComponent(ipField, 100, 100, 100)
.addComponent(label1)
.addComponent(portField, 100, 100, 100)
.addComponent(ipButton)
.addComponent(ipLabel)
.addComponent(historyButton)
.addComponent(connectionStatus)
.addComponent(connectionStatus1))
);
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(scrollPane)
.addGroup(layout.createSequentialGroup()
.addComponent(label)
.addComponent(ipField, 20, 20, 20)
.addComponent(label1)
.addComponent(portField, 20, 20, 20)
.addComponent(ipButton)
.addComponent(ipLabel)))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(textField)
.addComponent(button)
.addComponent(historyButton))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(status)
.addComponent(connectionStatus))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(yourIp)
.addComponent(connectionStatus1))
);
setTitle("P2P chat");
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
}