代碼給出了空指針異常的錯誤..... 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