真是乱七八糟^_^^_^!首先比较那个事件源触发的ActionEvent,可以使用e.getSource();不过要强制转换成相应的对象,如是Button事件,就用(Button)e.getSource();
使用e.getActionCommand()返回组件上面的title,然后比较可以确定是那个事件源!其次字符串转换为相应的基本类型,如int , float!如下:
Integer.parseInt( s );将字符串s转换为int
Float.parseFloat( s );将字符串转换为float

解决方案 »

  1.   

    把所有的e.target==pingjun改一下
    e.getSource() == pingjun
      

  2.   

    楼上说的很对,改正后的代码如下(刚刚调试通过),自己慢慢看吧,修改过的地方已经加了注释了:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;public class SimpleArithmetic extends Applet implements ActionListener
    {
      Label prompt1;
      TextField input1;
      Label prompt2;
      TextField input2;
      Label output;
      Button jia;
      Button jian;
      Button cheng;
      Button chu;
      Button zuidazhi;
      Button pingjun;
      
      public void init()
      {
          prompt1 = new Label("请输入一个整数:");
          input1 = new TextField(4);
          prompt2 = new Label("请输入一个浮点数:");
          input2 = new TextField(6);
          output = new Label("运算结果      ");  //创建output并初始化
          jia = new Button("加");                //创建jia并初始化,以下类似
          jian = new Button("减");
          cheng = new Button("乘");
          chu = new Button("除");
          zuidazhi = new Button("最大值");;
          pingjun = new Button("平均值");;
          add(prompt1);
          add(input1);
          add(prompt2);
          add(input2);
          add(output);             //输出标签添加到Applet,接下来的也是一样
          add(jia);
          add(jian);
          add(cheng);
          add(chu);
          add(zuidazhi);
          add(pingjun);       
          jia.addActionListener(this);
          jian.addActionListener(this);
          cheng.addActionListener(this);
          chu.addActionListener(this);
          zuidazhi.addActionListener(this);
          pingjun.addActionListener(this);
       }
       
       public void actionPerformed(ActionEvent e)
       {
        if(e.getSource()==jia)     //target改为getSource() 
            output.setText("相加值为:"+(Integer.parseInt(input1.getText())+Float.valueOf(input2.getText()).floatValue()));     else if(e.getSource()==jian)
            output.setText("相减值为:"+(Integer.parseInt(input1.getText())-Float.valueOf(input2.getText()).floatValue()));   //浮点数还要用floatValue()方法转换,以下类似。并去掉e.toString(),因为没用
                    else if(e.getSource()==cheng)
            output.setText("相乘值为:"+(Integer.parseInt(input1.getText())*Float.valueOf(input2.getText()).floatValue()));
        else if(e.getSource()==chu)
            output.setText("相除值为:"+(Integer.parseInt(input1.getText())/Float.valueOf(input2.getText()).floatValue()));
        else if(e.getSource()==zuidazhi)
            output.setText("最大值为:"+Math.max(Integer.parseInt(input1.getText()),Float.valueOf(input2.getText()).floatValue()));
        else if(e.getSource()==pingjun)
            output.setText("平均值为:"+((Integer.parseInt(input1.getText())+Float.valueOf(input2.getText()).floatValue())/2));         
       }
    }
      

  3.   

    除了改e.target为e.getSource()外,你的output,jia ,jian ,cheng ,chu ,zuidazhi , pingjun等对象都没有创建,用以下语句创建:
         output = new Label("运算结果      ");  
         jia = new Button("加");       
         jian = new Button("减");
         cheng = new Button("乘");
         chu = new Button("除");
         zuidazhi = new Button("最大值");
         pingjun = new Button("平均值");
    并将其加入到Applet,使用如下语句:
        add(output);            
        add(jia);
        add(jian);
        add(cheng);
        add(chu);
        add(zuidazhi);
        add(pingjun);
    最后还有在转换浮点数的地方的valueOf()方法后加floatValue()方法,并且将e.toString()去掉,刚才的程序中有两句多了个分号:
        zuidazhi = new Button("最大值");;
        pingjun = new Button("平均值");;
    去掉一个就行了。
      

  4.   

    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;public class SimpleArithmetic extends Applet implements ActionListener
    {
      Label prompt1;
      TextField input1;
      Label prompt2;
      TextField input2;
      Label output;
      Button jia;
      Button jian;
      Button cheng;
      Button chu;
      Button zuidazhi;
      Button pingjun;
      
      public void init()
      {
         prompt1=new Label("请输入一个整数:");
         input1=new TextField(4);
         prompt2=new Label("请输入一个浮点数:");
         input2=new TextField(6);
                jia = new Button("加");                //创建jia并初始化,以下类似
          jian = new Button("减");
          cheng = new Button("乘");
          chu = new Button("除");
          zuidazhi = new Button("最大值");;
          pingjun = new Button("平均值");;
         add(prompt1);
         add(input1);
         add(prompt2);
         add(input2);
         add(jia);
          add(jian);
          add(cheng);
          add(chu);
          add(zuidazhi);
          add(pingjun);
          jia.addActionListener(this);
          jian.addActionListener(this);
          cheng.addActionListener(this);
          chu.addActionListener(this);
          zuidazhi.addActionListener(this);
          pingjun.addActionListener(this);
       }
       
       public void actionPerformed(ActionEvent e)
       {
         if(e.getSource()==jia)
            output.setText("相加值为:"+String.valueOf(Integer.parseInt(input1.getText()) +Float.parseFloat(input2.getText()))+e.toString());
    ...      
       }
    }
      

  5.   

    搞定了
    谢谢各位
    特别是kaidu(Roger)
    我参考你的