这个简单的applet中单击按钮事件为什么不能触发呀!!!!!!!! Button 没有加事件侦听器bt.addActionListener(this); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以下代码测试通过:import java.awt.event.*;import java.applet.*;import java.awt.*;import java.util.EventObject;public class TestApplet extends Applet implements ActionListener{ private String s=null; private TextField tf; private Button bt; private Label lb; public void init(){ s="This is a test"; tf=new TextField("one"); this.add(tf); bt=new Button("button"); bt.addActionListener(this); this.add(bt); lb=new Label("this is a label"); this.add(lb); } public void actionPerformed(ActionEvent ae) { System.out.println(ae.getSource().toString()); if (ae.getSource() == bt) { //tfAnswer.setText("You clicked the JButton"); //bt.setLabel("this is a test"); tf.setText("DDDDDDDDDDDDDDD"); } }} 没有给按钮对象注册事件,怎么会有反应呢?楼上给你补上了: bt.addActionListener(this); 聊天系统单人聊天系统 问题!!!! 全通教育笔试题求解 关于在读取输入流时的while循环和read方法 再请教java socket接收发送 标签中的小问题 使用过cmppApi3.0 for java的进来,急! jboss能够设置虚拟目录吗 高分求教:谁能用贪心算法来解决这个问题?在线等待 小妹妹有难,请大虾们助我一吧! 单线程处理多个Task问题 救命呀,救命呀,100分,高手帮我 请问
import java.applet.*;
import java.awt.*;
import java.util.EventObject;public class TestApplet extends Applet implements ActionListener{
private String s=null;
private TextField tf;
private Button bt;
private Label lb; public void init(){
s="This is a test";
tf=new TextField("one");
this.add(tf);
bt=new Button("button");
bt.addActionListener(this);
this.add(bt);
lb=new Label("this is a label");
this.add(lb);
} public void actionPerformed(ActionEvent ae) {
System.out.println(ae.getSource().toString());
if (ae.getSource() == bt) {
//tfAnswer.setText("You clicked the JButton");
//bt.setLabel("this is a test");
tf.setText("DDDDDDDDDDDDDDD");
}
}}
楼上给你补上了: bt.addActionListener(this);