代码给出了空指针异常的错误..... wat能做什么?Java GUI编程
import java.awt.event.*;
import javax.swing.*;
public class Gui implements ActionListener{
JButton button;
public Gui(){
JFrame frame=new JFrame();
JButton button =new JButton("click me!");
button.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(button);
frame.setSize(270,300);
frame.setVisible(true);
}
public static void main(String[] args){
new Gui();
}
public void actionPerformed(ActionEvent e){
button.setText("I've been clicked");
}
}
我认为你需要尝试GUI开发之前,了解一些更多关于Java。 – Jivings
另请参阅[初始线程](http://download.oracle.com/javase/tutorial/uiswing/concurrency/initial.html)。 – trashgod