import java.applet.*;
import java.awt.*;
import java.awt.event.*;//写一个按钮类的子类, 增加一些新的功能:
class MyButton extends Button implements ActionListener,TextListener
{
TextArea text1,text2; //类的成员变量。
MyButton(String s)
{
super(s); //调用父类的构造方法。
text1 = new TextArea(8,8);
text2 = new TextArea(10,10);
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 J3 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");
}
}
/*<applet code=J3.class width=200 height=300>
</applet>*/
//上面这段代码用了三个监视器,我对其整体功能不大理解,这三个监视器是如何调用的,请具体指点!
import java.awt.*;
import java.awt.event.*;//写一个按钮类的子类, 增加一些新的功能:
class MyButton extends Button implements ActionListener,TextListener
{
TextArea text1,text2; //类的成员变量。
MyButton(String s)
{
super(s); //调用父类的构造方法。
text1 = new TextArea(8,8);
text2 = new TextArea(10,10);
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 J3 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");
}
}
/*<applet code=J3.class width=200 height=300>
</applet>*/
//上面这段代码用了三个监视器,我对其整体功能不大理解,这三个监视器是如何调用的,请具体指点!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货