import java.awt.event.*;
import javax.swing.*;
public class hello implements ActionListener {
JButton button;
public static void main(String[] args){
hello hello1 = new hello();
hello1.go();
}
public void go(){
JFrame frame = new JFrame();
button =new JButton("click me");
button.addActionListener(this);
frame.getContentPane().add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
button.setText("clicked!");
}
}
hello.java:4: 错误: hello不是抽象的, 并且未覆盖ActionListener中的抽象方法actionPerformed()
public class hello implements ActionListener {
^
hello.java:16: 错误: 不兼容的类型: hello无法转换为ActionListener
button.addActionListener(this);
^
注: 某些消息已经过简化; 请使用 -Xdiags:verbose 重新编译以获得完整输出
2 个错误
运行以上代码报错如上,说我没有没有覆盖接口中的方法,可是命名覆盖了啊,这个接口不是就一个方法吗?写了啊,为什么不行呢?