-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatClient.java
More file actions
47 lines (37 loc) · 927 Bytes
/
Copy pathChatClient.java
File metadata and controls
47 lines (37 loc) · 927 Bytes
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
import java.awt.*;
import java.awt.event.*;
/**
* @author HyperToxic
* 添加关闭事件响应
*/
public class ChatClient extends Frame {
TextField tf = new TextField();
TextArea ta = new TextArea();
public static void main(String[] args) {
new ChatClient().launchFrame();
}
public void launchFrame() {
setLocation(400, 300);
setSize(300, 300);
add(tf, BorderLayout.SOUTH);
add(ta, BorderLayout.NORTH);
this.pack();
setTitle("聊天小程序(by guohao:)");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
tf.addActionListener(new TextFieldListener());
setVisible(true);
}
private class TextFieldListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent action) {
// TODO Auto-generated method stub
String s = tf.getText().trim();
ta.setText(s);
tf.setText("");
}
}
}