1. [代码]java代码
01 |
05 | import java.applet.*; |
06 | import java.awt.*; |
07 | import java.awt.event.*; |
08 | |
09 | public class myApplet extends Applet implements ActionListener,TextListener |
10 | { |
11 | TextFieldtf; |
12 | TextArea |
13 | |
14 | public void init() |
15 | { |
16 | tf= new TextField( 45 ); |
17 | ta= new TextArea ( 5 , 45 ); |
18 | this .add(tf); |
19 | this .add(ta); |
20 | tf.addActionListener( this ); |
21 | tf.addTextListener( this ); |
22 | } |
23 | //单行文本(TextEvent)改变引发的事件 |
24 | public void textValueChanged(TextEvent e) |
25 | { |
26 | if (e.getSource()==tf) |
27 | ta.setText(((TextField)e.getSource()).getText()); |
28 | } |
29 | //在单行文本按回车引发的时间 |
30 | public void actionPerformed(ActionEvent e) |
31 | { |
32 | if (e.getSource()==tf) |
33 | { |
34 | ta.setText( "" ); //回车,文本域清空 |
35 | } |
36 | } |
37 | } |