case 12:
{n=c1*c2;
text.setText(String.valueOf(n));
break;
}
case 13:
if(c2!=0)
{n=c1/c2;
text.setText(String.valueOf(n));
break;
}
}
}if(j.indexOf(s)>14)
text.setText("0");}
}

解决方案 »

  1.   

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class jisuan extends Applet implements ActionListener {
    TextField text;
    Button b1,b2, b3, b4, b5, b6, b7, b8, b9, b10,
    b11,b12,b13,b14,b15,b16;
    Panel p1, p2, p3, p4; String Sign = " "; //存放运算符   //
    double c1 = 0.0, c2 = 0.0;        //注意这两个变量要设成全局的

    GridLayout net;
    public void init() {
    net = new GridLayout(5, 1);
    setLayout(net);
    text = new TextField("0", 15);
    add(text);
    p1 = new Panel();
    p2 = new Panel();
    p3 = new Panel();
    p4 = new Panel();
    p1.setLayout(new GridLayout(1, 4));
    p2.setLayout(new GridLayout(1, 4));
    p3.setLayout(new GridLayout(1, 4));
    p4.setLayout(new GridLayout(1, 4));
    b1 = new Button("7");
    b1.addActionListener(this);
    b2 = new Button("8");
    b2.addActionListener(this);
    b3 = new Button("9");
    b3.addActionListener(this);
    b4 = new Button("ce");
    b4.addActionListener(this);
    b5 = new Button("4");
    b5.addActionListener(this);
    b6 = new Button("5");
    b6.addActionListener(this);
    b7 = new Button("6");
    b7.addActionListener(this);
    b8 = new Button("+");
    b8.addActionListener(this);
    b9 = new Button("1");
    b9.addActionListener(this);
    b10 = new Button("2");
    b10.addActionListener(this);
    b11 = new Button("3");
    b11.addActionListener(this);
    b12 = new Button("-");
    b12.addActionListener(this);
    b13 = new Button("0");
    b13.addActionListener(this);
    b14 = new Button("*");
    b14.addActionListener(this);
    b15 = new Button("/");
    b15.addActionListener(this);
    b16 = new Button("=");
    b16.addActionListener(this);
    p1.add(b1);
    p1.add(b2);
    p1.add(b3);
    p1.add(b4);
    p2.add(b5);
    p2.add(b6);
    p2.add(b7);
    p2.add(b8);
    p3.add(b9);
    p3.add(b10);
    p3.add(b11);
    p3.add(b12);
    p4.add(b13);
    p4.add(b14);
    p4.add(b15);
    p4.add(b16);
    add(p1);
    add(p2);
    add(p3);
    add(p4);
    }
    public void actionPerformed(ActionEvent e) {
    String j = "0123456789+-*/=ce";
    //double c1 = 0.0, c2 = 0.0;
    //String Sign = " "; //存放运算符
    String s = "0"; //存放当前被点击的按扭的名字
    double n; if (e.getSource() == b1)
    s = "7";
    if (e.getSource() == b2)
    s = "8";
    if (e.getSource() == b3)
    s = "9";
    if (e.getSource() == b4)
    s = "ce";
    if (e.getSource() == b5)
    s = "4";
    if (e.getSource() == b6)
    s = "5";
    if (e.getSource() == b7)
    s = "6";
    if (e.getSource() == b8)
    s = "+";
    if (e.getSource() == b9)
    s = "1";
    if (e.getSource() == b10)
    s = "2";
    if (e.getSource() == b11)
    s = "3";
    if (e.getSource() == b12)
    s = "-";
    if (e.getSource() == b13)
    s = "0";
    if (e.getSource() == b14)
    s = "*";
    if (e.getSource() == b15)
    s = "/";
    if (e.getSource() == b16)
    s = "=";
    if (j.indexOf(s) >= 0 && j.indexOf(s) <= 9) {
    if (text.getText().equals("0"))
    text.setText(s);
    else
    text.setText(text.getText() + s);
    } if (j.indexOf(s) >= 10 && j.indexOf(s) <= 13) {
    c1 = Double.valueOf(text.getText()).doubleValue();
    Sign = s;
    text.setText("0");
    } if (j.indexOf(s) == 14) {
    c2 = Double.valueOf(text.getText()).doubleValue();
    switch (j.indexOf(Sign)) {
    case 10 :
    {
    n = c1 + c2;
    text.setText(String.valueOf(n));
    break;
    }
    case 11 :
    {
    n = c1 - c2;
    text.setText(String.valueOf(n));
    break;
    }
    }
    }
    }
    }
      

  2.   

    能具体一点吗,怎么做呢,我是刚刚学java的,我想会有更简洁的方法可以实现相同的功能,可是我目前只学了一些applet中的基本组件而已啊!