import java.awt.*;
import java.awt.event.*;public class W4 extends Frame implements ActionListener {
Button btn1,btn2;
TextField f;
W4(){
super("Window4");
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setSize(350,200);
btn1 = new Button("显示");
btn2 = new Button("退出");
f = new TextField(20);
setLayout(new FlowLayout());
add(f);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
show();
}
public static void main(String args[]){
new W4();
}
public void actionPeformed(ActionEvent e){
f.setText("你按下了“"+e.getActionCommand()+"“按钮");
if(e.getSource() == btn2){
System.exit(0);
}
}}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
该程序编译不过,提示信息为:W4.java:4: W4 is not abstract and does not override abstract method actionPerfor
med(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class W4 extends Frame implements ActionListener {
^
1 error麻烦各位给看下,不知怎么改。
import java.awt.event.*;public class W4 extends Frame implements ActionListener {
Button btn1,btn2;
TextField f;
W4(){
super("Window4");
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setSize(350,200);
btn1 = new Button("显示");
btn2 = new Button("退出");
f = new TextField(20);
setLayout(new FlowLayout());
add(f);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
show();
}
public static void main(String args[]){
new W4();
}
public void actionPeformed(ActionEvent e){
f.setText("你按下了“"+e.getActionCommand()+"“按钮");
if(e.getSource() == btn2){
System.exit(0);
}
}}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
该程序编译不过,提示信息为:W4.java:4: W4 is not abstract and does not override abstract method actionPerfor
med(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class W4 extends Frame implements ActionListener {
^
1 error麻烦各位给看下,不知怎么改。
就是说你不是抽象的类,不可以重写抽象类中的方法。
^_^. 还有我用1.5编译后,显示:
F:\>javac W4.java
注意: W4.java 使用或覆盖了已过时的 API。
注意: 要了解详细信息,请使用 -Xlint:deprecation 重新编译。F:\>javac -Xlint:deprecation W4.java
W4.java:25: 警告: [deprecation] java.awt.Window 中的 show() 已过时
show();
^
1 警告
public void actionPerformed(ActionEvent e){}