frame1 不是抽象的,并且未覆盖 java.awt.event.ActionListener 中的抽象方法 actionPerformed

ljydomybest 2008-01-25 10:19:44
import java.awt.*;
import java.awt.event.*;
public class fram extends Frame implements ActionListener {
static Button btn;
fram(){
super("Frame with Button");
setVisible(true);
btn=new Button("退出");
setBackground(Color.yellow);
setForeground(Color.blue);

//setResizable(false);//不可更改大小
//setSize(380,500);//设置大小

add(btn);
pack();
btn.addActionListener(this);
}
static void addPerformed(ActionEvent e){
if (e.getSource()==btn) {
System.exit(0);
}
}
public static void main(String[] args) {
fram frm =new fram();// TODO Auto-generated method stub

}

}
frame1.java:3: frame1 不是抽象的,并且未覆盖 java.awt.event.ActionListener 中的抽象方法 actionPerformed(java.awt.event.ActionEvent)
import java.awt.*;
import java.awt.event.*;

public class pel extends Frame implements ActionListener {
static Button btn;
pel() {
super("Panel with button");
Panel p1 = new Panel();
add(p1);
btn=new Button("exit");
p1.add(btn);
pack();
btn.addActionListener(this);
}

static void addPerformed(ActionEvent e) {
if (e.getSource()=btn) {
System.exit(0);
}
}

public static void main(String[] args) {
pel p = new pel();
}
}
F:\000\work\111>javac pel.java
pel.java:4: pel 不是抽象的,并且未覆盖 java.awt.event.ActionListener 中的抽象方
法 actionPerformed(java.awt.event.ActionEvent)
public class pel extends Frame implements ActionListener {
^
pel.java:17: 意外的类型
需要: 变量
找到: 值
if (e.getSource()=btn) {
^
2 错误
...全文
908 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
WodERP 2009-03-31
  • 打赏
  • 举报
回复
要注意大小写啊,朋友
Java是大小写有关的语言
newredhat 2008-02-14
  • 打赏
  • 举报
回复
oo
dracularking 2008-02-12
  • 打赏
  • 举报
回复
提示也已经给出了
你实现了某某接口的类必须实现所继承的抽象方法

ActionListener.actionPerformed(ActionEvent)
liz19871016 2008-02-12
  • 打赏
  • 举报
回复
第一个错误是方法名不对。应该是actionPerformed(ActionEvent e){}
第二个错误是~~。应该是if (e.getSource() == btn)

58,453

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧