⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histogram.java

📁 学生成绩管理系统:能输入学科
💻 JAVA
字号:
package 学生考试成绩分析程序;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;import java.util.*;public class Histogram extends JFrame implements ActionListener{   static int[] count={0,0,0,0,0};   static int m;   static int sum=0;    JButton jbExit;    static String[] class1;    static String[] name;    static String[] score;    static int icount=0;    String[] line;    public Histogram(String Class,String course){             try{           BufferedReader input =new BufferedReader(new FileReader("score.txt"));           String L=input.readLine();           double sc=0;           String s3,s4;                   StringTokenizer scanner1=new StringTokenizer(L,"*");           m=scanner1.countTokens();          line=new String[m];          class1=new String[m/7];          name=new String[m/7];          score=new String[m/7];          for(int j=0;scanner1.hasMoreTokens();j++)          {              line[j]=scanner1.nextToken();          }           for(int j=0,n=1;j<m;j++,n++)                     {                         if(n==1){                                                         class1[icount]=line[j];                             name[icount]=line[j+1];                             score[icount]=line[j+4];                             icount++;                          }                         if(n==7){                             n=0;                         }                     }          StringTokenizer scanner3=new StringTokenizer(Class);          StringTokenizer scanner4=new StringTokenizer(course);          s3=scanner3.nextToken();          s4=scanner4.nextToken();            for(int k=0;k<m/7;k++)          {              if((class1[k].equals(s3))&&(name[k].equals(s4)))              {               sc=Double.parseDouble(score[k]);               if(sc<59&&sc>=0)                   count[0]++;               if(sc<69&&sc>=60)                   count[1]++;               if(sc<79&&sc>=70)                   count[2]++;               if(sc<89&&sc>=80)                   count[3]++;               if(sc<=100&&sc>=90)                   count[4]++;               sum++;         }      }                      input.close();      }      catch(Exception es){           sum=0;            icount=0;            m=0;            for(int d=0;d<5;d++)            count[d]=0;          JOptionPane.showMessageDialog(null, "分析失败");      }      jbExit=new JButton("EXIT");       JPanel jpExit=new JPanel();       jpExit.add(jbExit);       jbExit.addActionListener(this);       getContentPane().add(new RectPanel(),BorderLayout.CENTER);       getContentPane().add(jpExit,BorderLayout.SOUTH);        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);        this.setTitle("柱状图");        this.setLocation(400,300);        this.setSize(500,380);        this.setVisible(true);          }class RectPanel extends JPanel{    protected void paintComponent(Graphics g){        int i=(getHeight()/9*8-getHeight()/8)/5;        int j=(getWidth()/7*6)/10;        super.paintComponent(g);        g.setColor(Color.LIGHT_GRAY);        g.fillRect(getWidth()/10,getHeight()/8,getWidth()/7*6,getHeight()/4*3);         g.setColor(Color.BLACK);        g.drawString("人数", getWidth()/27,getHeight()/15);        g.setColor(Color.BLACK);        g.drawString("25", getWidth()/27,getHeight()/8);          g.setColor(Color.BLACK);        g.drawString("20", getWidth()/27,getHeight()/8+i);        g.setColor(Color.BLACK);        g.drawString("15", getWidth()/27,getHeight()/8+2*i);        g.setColor(Color.BLACK);        g.drawString("10", getWidth()/27,getHeight()/8+3*i);        g.setColor(Color.BLACK);        g.drawString("5", getWidth()/25,getHeight()/8+4*i);        g.setColor(Color.BLACK);        g.drawString("0", getWidth()/25,getHeight()/9*8);        g.setColor(Color.BLACK);        g.drawString("<60分", getWidth()/50*7,getHeight()/16*15);        g.setColor(Color.BLACK);        g.drawString("60-69分", getWidth()/50*7+2*j,getHeight()/16*15);        g.setColor(Color.BLACK);        g.drawString("70-79分", getWidth()/50*7+4*j,getHeight()/16*15);        g.setColor(Color.BLACK);        g.drawString("80-89分",getWidth()/50*7+6*j,getHeight()/16*15);        g.setColor(Color.BLACK);        g.drawString(">=90分", getWidth()/50*7+8*j,getHeight()/16*15);        g.setColor(Color.BLACK);        g.fillRect(getWidth()/50*7,getHeight()/8+getHeight()/4*3*(250-count[0]*10)/250,j,getHeight()/4*3*count[0]*10/250);        g.setColor(Color.BLACK);        g.fillRect(getWidth()/50*7+2*j,getHeight()/8+getHeight()/4*3*(250-count[1]*10)/250,j,getHeight()/4*3*count[1]*10/250);        g.setColor(Color.BLACK);        g.fillRect(getWidth()/50*7+4*j,getHeight()/8+getHeight()/4*3*(250-count[2]*10)/250,j,getHeight()/4*3*count[2]*10/250);        g.setColor(Color.BLACK);        g.fillRect(getWidth()/50*7+6*j,getHeight()/8+getHeight()/4*3*(250-count[3]*10)/250,j,getHeight()/4*3*count[3]*10/250);        g.setColor(Color.BLACK);        g.fillRect(getWidth()/50*7+8*j,getHeight()/8+getHeight()/4*3*(250-count[4]*10)/250,j,getHeight()/4*3*count[4]*10/250);        g.setColor(Color.BLACK);           }}public void actionPerformed(ActionEvent e)    {        if(e.getSource()==jbExit){            sum=0;            icount=0;            m=0;       for(int d=0;d<5;d++)            count[d]=0;            this.setVisible(false);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -