1 回答
TA贡献1797条经验 获得超6个赞
将所有 GUI 组件的变量声明移出init()方法,但仍在Calculator类内,这样它们对于actionPerformed可能需要访问它们的其他方法(例如 )是可见的:
public class Calculator extends DialogProgram implements ActionListener{
JButton b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,bm,bd,ba,bs,bdec,bc;
DoubleField screen;
JPanel P, P1, P2;
public void init() {
P= new JPanel(); // main panel
P1= new JPanel(); // panel for buttons
P2= new JPanel(); // panel for screen
// continue setting up the rest of the GUI...
}
public void actionPerformed (ActionEvent e) {
String clicked = e.getActionCommand();
if (clicked.equals("ba")) {
screen.setText("+");
}
}
}
添加回答
举报