这是我的代码:
import javax.swing.*;
import java.awt.*;
public class FirstGui extends JFrame {
private JLabel label;
private JButton button;
public FirstGui() {
setLayout(new FlowLayout());
button = new JButton("Click for sex");
add(button);
label = new JLabel("");
add(label);
event e = new event();
button.addActionListener(e);
}
public class event implements ActionListener {
public void actionPerformed(ActionEvent e) {
label.setText("how you can see wors here");
}
}
public static void main(String [] args) {
FirstGui gui = new FirstGui();
gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
gui.setSize(200, 200);
gui.setTitle("Title");
gui.setVisible(true);
}
}
它会产生一个错误:
ActionEvent 无法解析为 FirstGui.java /Test/src 第 26 行 Java 问题
ActionListener 无法解析为 FirstGui.java /Test/src 第 24 行 Java 问题
AbstractButton 类型中的方法 addActionListener(ActionListener) 不适用于参数 (FirstGui.event) FirstGui.java /Test/src 第 21 行 Java 问题
有什么问题???我是 Java 新手。