我在一行代码中遇到 4 个错误
读取“public action void actionPerformed(ActionEvent event){”的行两次获得“Illegal start of action”和两次“; expected”。
我从 Head First Java 书中复制了这段代码,为什么它不能编译?
import javax.swing.*;
import java.awt.event.*;
public class SimpleGui1 implements ActionListener{
Jbutton button;
public static void main (String [] args) {
SimpleGui1 gui = new SimpleGui1();
gui.go();
}
public void go(){
JFrame frame = new JFrame();
button = new JButton("Click");
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("I've been clicked.");
} //close actionPerformed
} //close go()
}