-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseTextEvent.java
More file actions
41 lines (39 loc) · 856 Bytes
/
Copy pathUseTextEvent.java
File metadata and controls
41 lines (39 loc) · 856 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
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.applet.Applet;
public class UseTextEvent extends Applet implements ActionListener, TextListener
{
TextField tOld;
TextArea tNew;
Panel p;
public void init()
{
tOld = new TextField(25);
tNew = new TextArea(8,25);
// 添加事件监听者
tOld.addActionListener(this);
tOld.addTextListener(this);
// 设置界面
p = new Panel(new BorderLayout());
p.add(tOld, BorderLayout.NORTH);
p.add(tNew, BorderLayout.SOUTH);
add(p);
}
// 响应文本事件
public void textValueChanged(TextEvent e)
{
if (e.getSource() == tOld)
{
tNew.setText(tOld.getText());
}
}
// 响应动作事件
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == tOld)
{
tNew.setText("");
}
}
}