就是一个文本文件!问题非常简单,就是我不会java

解决方案 »

  1.   

    这个txt用来放分数而已?还是连班级、姓名以及分数放在一起?
      

  2.   

    帮你改了一些东西,前面部分的功能保留,实现了统计部分的功能,你看看,代码如下:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class applet3 extends WindowAdapter  implements ActionListener
    {
       int i=0;
       String str="";   Frame f;
       Button b1,b2,b3;
       TextArea ta,tb;
       FileDialog fd1;
       Font fo=new Font("",1,18);
       TextField t[]=new TextField[15];
       Panel p[]=new Panel[15];   public static void main(String args[])
       {
          applet3 that=new applet3();
          that.go();
       }
       public void go()
       {
          f=new Frame("金融班(200072)");
          b1=new Button("打开");
          b2=new Button("分数统计");
          b3=new Button("退出");
          ta=new TextArea("",0,0,3);
          tb=new TextArea("",0,0,3);
          fd1=new FileDialog(f,"打开",0);
           Font fo=new Font("Dialog",Font.BOLD,18);
           ta.setFont(fo);
          Panel p1=new Panel();
          Panel p2=new Panel();
          Panel p3=new Panel();
          Panel p4=new Panel();
          Panel p5=new Panel();
          f.setLayout(new GridLayout(1,3));
          f.add(p1);
          f.add(p2);
          f.add(p3);
          p1.setLayout(new BorderLayout());
          p1.add(b1,"North");
          p1.add(ta,"Center");
          p2.setLayout(new GridLayout(16,1));
          p2.add(new Label("分数"));
          for(i=0;i<15;i++)
          {
             p[i]=new Panel();
             t[i]=new TextField(3);
             p2.add(t[i]);
          }
          p3.setLayout(new BorderLayout());
          p3.add(b2,"North");
          p3.add(tb,"Center");      f.setBounds(100,100,370,300);
          f.setBackground(Color.green);
          f.addWindowListener(this);
          f.setVisible(true);       b1.addActionListener(this);
           b2.addActionListener(this);
           b3.addActionListener(this);
       }
       public void windowClosing(WindowEvent e)
       {
          System.exit(0);
       }
       public void actionPerformed(ActionEvent e)
       {
          int a1=0,a2=0,a4=0,a5=0,a3=0,a6=0;
              if(e.getSource()==b1)
                    {
                            fd1.setVisible(true);
                            int b;
                            File f1=new File(fd1.getDirectory(),fd1.getFile());                        int a=(int)f1.length();
                            byte buffer[]=new byte[a];
                            try
                              {
                                   FileInputStream rf=new FileInputStream(f1);
                                   b=rf.read(buffer,0,a);
                                   str=new String(buffer,0,b,"GB2312");
                              }
                            catch(IOException f)
                              {
                                   str="文件读取错误";
                              }
                            ta.setText(str);
                   }
              String s1="",s2="",s3="",s4="",s5="",s6="",s7="",s8="",s9="",s10="",
                     s11="",s12="",s13="",s14="",s15="";
              double    t1=0,t2=0,t3=0,t4=0,t5=0,t6=0,t7=0,t8=0,t9=0,t10=0,
                     t11=0,t12=0,t13=0,t14=0,t15=0,temp=0;
              int i=0,j=0;
              s1=t[0].getText();     s2=t[1].getText();
              s3=t[2].getText();     s4=t[3].getText();
              s5=t[4].getText();     s6=t[5].getText();
              s7=t[6].getText();     s8=t[7].getText();
              s9=t[8].getText();     s10=t[9].getText();
              s11=t[10].getText();     s12=t[11].getText();
              s13=t[12].getText();     s14=t[13].getText();
              s15=t[14].getText();
              try {
                t1 = Double.parseDouble(s1);
                t2 = Double.parseDouble(s2);
                t3 = Double.parseDouble(s3);
                t4 = Double.parseDouble(s4);
                t5 = Double.parseDouble(s5);
                t6 = Double.parseDouble(s6);
                t7 = Double.parseDouble(s7);
                t8 = Double.parseDouble(s8);
                t9 = Double.parseDouble(s9);
                t10 = Double.parseDouble(s10);
                t11 = Double.parseDouble(s11);
                t12 = Double.parseDouble(s12);
                t13 = Double.parseDouble(s13);
                t14 = Double.parseDouble(s14);
                t15 = Double.parseDouble(s15);
              } catch(Exception ex){JOptionPane.showMessageDialog(f,"十五个文本框必须填满,并且都必须输入数字!");return;}
              double f[]={t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15};
              for(i=0;i<15;i++)//冒泡排序,从高到低排列
              {
                 for(j=i;j<15;j++)
                 {
                    if(f[i]<f[j])
                    {
                         temp=f[i];
                         f[i]=f[j];
                         f[j]=temp;
                    }
                 }
              }
              for(i=0;i<15;i++)
              {
                 if(f[i]<49)
                 a1++;
                 if(f[i]>=50&&f[i]<59)
                 a2++;
                 if(f[i]>=60&&f[i]<69)
                 a3++;
                 if(f[i]>=70&&f[i]<79)
                 a4++;
                 if(f[i]>=80&&f[i]<89)
                 a5++;
                 if(f[i]>=90)
                 a6++;
              }          if(e.getSource()==b2)
              {
                java.text.DecimalFormat df=new java.text.DecimalFormat("#.##");
                String s="名次-----分数 \n";
                double scoreCount=0;
                 for(int ii=0;ii<f.length;ii++) {
                   scoreCount+=f[ii];
                   s+=" "+(ii+1)+" ----- "+f[ii]+"\n";
                 }
                 s+="-------------\n分数统计:\n";
                 s+="总分:"+scoreCount;
                 s+="\n平均分:"+df.format(scoreCount/15);
                 s+="\n-------------\n分数段统计:\n";
                 s+="49分以下: "+a1+" 人\n";
                 s+="50~~59分: "+a2+" 人\n";
                 s+="60~~69分: "+a3+" 人\n";
                 s+="70~~79分: "+a4+" 人\n";
                 s+="80~~89分: "+a5+" 人\n";
                 s+="90分以上: "+a6+" 人\n";
                 this.tb.setText(s);
              }
       }
    }