java代码写亲戚计算器 java的计算器代码( 五 )


private boolean isChoiseOptType=true;
public void init() {
b0 = new Button("0");
b0.addActionListener(this);
b1 = new Button("1");
b1.addActionListener(this);
b2 = new Button("2");
b2.addActionListener(this);
b3 = new Button("3");
b3.addActionListener(this);
b4 = new Button("4");
b4.addActionListener(this);
b5 = new Button("5");
b5.addActionListener(this);
b6 = new Button("6");
b6.addActionListener(this);
b7 = new Button("7");
b7.addActionListener(this);
b8 = new Button("8");
b8.addActionListener(this);
b9 = new Button("9");
b9.addActionListener(this);
bp = new Button(".");
bp.addActionListener(this);
ba = new Button("+");
ba.addActionListener(this);
bs = new Button("-");
bs.addActionListener(this);
bm = new Button("*");
bm.addActionListener(this);
bd = new Button("/");
bd.addActionListener(this);
be = new Button("=");
be.addActionListener(this);
bc = new Button("c");
bc.addActionListener(this);
bt = new Button("退格");
bt.addActionListener(this);
bf = new Button("1/x");
bf.addActionListener(this);
bh = new Button("+/-");
bh.addActionListener(this);
this.setTitle("计算机");
this.setLayout(null);
this.setSize(260, 300);
this.setResizable(false);
GridLayout grid = new GridLayout(4, 5);
pan.setLayout(grid);
pan.setBounds(20, 60, 150, 120);
textField.setBounds(20, 35, 150, 20);
textField.setBackground(Color.cyan);
textField.setHorizontalAlignment(textField.RIGHT);
textField.setEditable(false);
pan.add(b1);
pan.add(b2);
pan.add(b3);
pan.add(ba);
pan.add(bc);
pan.add(b4);
pan.add(b5);
pan.add(b6);
pan.add(bs);
pan.add(bt);
pan.add(b7);
pan.add(b8);
pan.add(b9);
pan.add(bm);
pan.add(bf);
pan.add(b0);
pan.add(bh);
pan.add(bp);
pan.add(bd);
pan.add(be);
this.add(textField);
this.add(pan);
}
public static void main(String[] args) {
Calculator frm = new Calculator();
frm.init();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
}
@SuppressWarnings("static-access")
@Override
public void actionPerformed(ActionEvent e) {
String value="https://www.04ip.com/post/0";
if (e.getSource().equals(b0)) {
this.temp.append(b0.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b1)) {
this.temp.append(b1.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b2)) {
this.temp.append(b2.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b3)) {
this.temp.append(b3.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b4)) {
this.temp.append(b4.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b5)) {
this.temp.append(b5.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b6)) {
this.temp.append(b6.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b7)) {
this.temp.append(b7.getLabel());
this.textField.setText(this.temp.toString());
isChoiseOptType=false;
} else if (e.getSource().equals(b8)) {
this.temp.append(b8.getLabel());
this.textField.setText(this.temp.toString());

推荐阅读