我是 Java 新手,目前正在通过HeadFirst Java 书籍自学。我正在浏览 GUI 界面,书中的代码似乎没有运行,
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();
JButton 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("I have been clicked");
}
}
The exception :
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
有人可以告诉我有什么问题吗?