如何防止我的當前代碼發生此錯誤?我很抱歉我的邏輯非常業餘。無法從靜態上下文錯誤中引用按鈕變量
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);
}
}
你在哪裏得到的錯誤? –
你在哪一行出錯? –
主要方法的第一行 – Jay