import java.applet.*; import java.awt.*; import java.awt.event.*;
class MyButton extends Button implements TextListener,ActionListener { TextArea text1,text2; MyButton(String s) { super(s); text1=new TextArea(10,10); text2=new TextArea(20,20); text1.addTextListener(this); this.addActionListener(this); } public void textValueChanged(TextEvent e) { text2.setText(text1.getText()); } public void actionPerformed(ActionEvent e) { text1.setText(null); } }
public class Test4 extends Applet implements ActionListener { MyButton button; public void init() { button=new MyButton("点击看我能发生什么?"); button.addActionListener(this); add(button.text1);add(button.text2);add(button); } public void actionPerformed(ActionEvent e) { button.text1.setText(button.getLabel()); button.text2.setText("ok!"); }
}
大家说下结果是什么?
能告诉我为什么 button.text2.setText("ok!"); 没执行呢?