我的代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Events1 extends JFrame {
private JLabel label;
private JButton button;
public Events1() {
setLayout(new FlowLayout());
label = new JLabel("");
button = new JButton("Click for text");
add(button);
add(label);
event e = new event();
button.addActionListener(e);
}
public class event implements ActionListener {
public void actionPerfomed(ActionEvent e) {
label.setText("See motherfucker it does do stuff");
}
}
public static void main(String[] args) {
Events1 window = new Events1();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(500, 500); //.pack();
window.setVisible(true);
window.setTitle("Attempt 2");
}
}
基本上我是GUI的新手并在尝试编译上述代码时收到错误消息:
Events1.java:25: error: Events1.event is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
public class event implements ActionListener {
^
1 error
我基本上是根据有关Oracle Docs的信息制作了这段代码,并且非常混淆了为什么这不起作用/如何修复它。
非常感谢任何帮助。
答案 0 :(得分:2)
您在覆盖方法中有拼写错误
public void actionPerformed(ActionEvent e)
这就是为什么你应该使用@Override注释来覆盖这些操作的覆盖方法和IDE支持。