import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class Applet1 extends Frame implements ActionListener { Button bt1,bt2;
Label 11;
Applet1(){
super("Window1");
addWindowListener(this);
setSize(400,200);
bt1=new Button("111");
bt2=new Button("222");
11=new Label("点击任意按钮");
setLayout(new FlowLayout());
add(11);
add(bt1);
add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
show();
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowOpen(WindowEvent e);
public void windowClose(WindowEvent e);
public void windowIconified(WindowEvent e);
public void windowDeiconified(WindowEvent e);
public void windowActivate(WindowEvent e);
public void windowDeactivate(WindowEvent e);
public static void main(String args[]){
new Applet1();
}
public void actionPerformed(ActiveEvent e){
11.setText("你按下的是"+e.getActionCommand()+"");
}}
import java.awt.event.*;
import java.applet.*;public class Applet1 extends Frame implements ActionListener { Button bt1,bt2;
Label 11;
Applet1(){
super("Window1");
addWindowListener(this);
setSize(400,200);
bt1=new Button("111");
bt2=new Button("222");
11=new Label("点击任意按钮");
setLayout(new FlowLayout());
add(11);
add(bt1);
add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
show();
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowOpen(WindowEvent e);
public void windowClose(WindowEvent e);
public void windowIconified(WindowEvent e);
public void windowDeiconified(WindowEvent e);
public void windowActivate(WindowEvent e);
public void windowDeactivate(WindowEvent e);
public static void main(String args[]){
new Applet1();
}
public void actionPerformed(ActiveEvent e){
11.setText("你按下的是"+e.getActionCommand()+"");
}}
解决方案 »
- java加密算法RSA
- The Bean Builder哪位有?给我发一个
- 高手请进:经典的智力题,用java怎么解啊.....
- Java SE 6之脚本引擎 让程序如虎添翼
- 想不通: 一个接口是另一个类的私有变量, 调用这个接口里的方法 ,会调用实现这个接口的类的相关方法 . ?? 如果有多个类实现了这个接口他怎
- 哪里有VisualAge for Java 3.0企业版下载啊?
- 怎样实现一个树型结构,并能够浏览整个磁盘的所以目录和文件!!(高分相送)
- 哪里有可视化的jCheckTree组件?
- 问一个比较简单的问题 frame 的 setSize()放在那里比较合适
- 关于redhat网站上下载的jre java-sun-1.6.0安装包的问题
- 求助
- 今天面试的几个题来分享一下
import java.awt.event.*;
import java.applet.*;class Test extends Frame implements ActionListener { Button bt1,bt2;
Label l11;
Test(){
super("Window1");
setSize(400,200);
bt1=new Button("111");
bt2=new Button("222");
l11=new Label("点击任意按钮");
setLayout(new FlowLayout());
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
add(l11);
add(bt1);
add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
show();
} public static void main(String args[]){
new Test();
} public void actionPerformed(ActionEvent e) {
l11.setText("你按下的是"+e.getActionCommand()+"");
}
一、利用适配器WindowAdapter,他实现了接口中所有方法,但是方法体是空的,所以你只要覆盖你需要覆盖的方法就可以了
二、不要用数字做变量名
三、最后public void actionPerformed(ActionEvent e)中,是ActionEvent不是ActiveEvent,你把我累死了,我用IDE工具去编辑才发现这个问题