如何防止我当前的代码发生此错误?我为我的逻辑非常业余而道歉。
public class jButExmp {
JFrame exmpFrame;
JButton Button1, Button2, Button3;
public jButExmp () {
exmpFrame.setLayout(new FlowLayout());
exmpFrame.setSize(250,150);
exmpFrame.setVisible(true);
exmpFrame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
exmpFrame.add(Button1);
exmpFrame.add(Button2);
exmpFrame.add(Button3);
}
public static void main(String[] args) {
exmpFrame = new JFrame ("Example Frame");
Button1 = new JButton ("1");
Button2 = new JButton ("2");
Button3 = new JButton ("3");
Button1.setSize(80, 30); //set size of button
Button1.setLocation(0,0);
Button1.setEnabled(true);
Button2.setSize(80,30);
Button2.setLocation(90, 0);
Button2.setEnabled(false);
}
}