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

📄 buttonlistener4.java

📁 学生成绩管理系统:能输入学科
💻 JAVA
字号:
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.*;/* * To change this template, choose Tools | Templates * and open the template in the editor. */import java.io.*;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.*;/** * * @author HSM */class ButtonListener4 implements ActionListener {    public void actionPerformed(ActionEvent e) {       final JFrame frame1 = new JFrame("Sorce_Analysis");        Container container = frame1.getContentPane();        frame1.setSize(600, 400);        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        int screenHeight = screenSize.height;        int screenWidth = screenSize.width;        int x = (screenWidth - frame1.getWidth()) / 2;        int y = (screenHeight - frame1.getHeight()) / 2;        frame1.setLocation(x, y);        frame1.setVisible(true);        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JLabel jLabel1 = new JLabel("成绩分析");        JLabel jLabel2 = new JLabel("年级:");        JLabel jLabel3 = new JLabel("专业:");        JLabel jLabel4 = new JLabel("班级:");        JLabel jLabel5 = new JLabel("课程:");        JLabel jLabel6 = new JLabel("        ");        JLabel jLabel7 = new JLabel("        ");        JLabel jLabel8 = new JLabel("        ");        JLabel jLabel9 = new JLabel("        ");        JLabel jLabel10 = new JLabel("");        JLabel jLabel11 = new JLabel("");        JLabel jLabel12 = new JLabel("");        final JTextField jtf1 = new JTextField(7);        final JTextField jtf2 = new JTextField(7);        final JTextField jtf3 = new JTextField(7);        final JTextField jtf4 = new JTextField(7);        JButton jbtSzfx = new JButton("   数字分析   ");        JButton jbtTxfx = new JButton("   图形分析   ");        JButton jbtBtfx = new JButton("   饼图分析   ");        JButton jbtQx = new JButton("        取消        ");        JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT));        JPanel p2 = new JPanel(new FlowLayout());        JPanel p3 = new JPanel(new FlowLayout());        JPanel p4 = new JPanel(new BorderLayout());        JPanel p5 = new JPanel(new BorderLayout());        final JPanel p6 = new JPanel(new BorderLayout());        JPanel p7 = new JPanel(new FlowLayout());        JPanel p8 = new JPanel(new FlowLayout());        JPanel p9 = new JPanel(new FlowLayout());        JPanel p10 = new JPanel(new GridLayout(3,1));        JPanel p11 = new JPanel(new GridLayout(5,0));        final JTextArea jtArea = new JTextArea(15,45);        p1.add(jLabel1);        p2.add(jLabel2);        p2.add(jtf1);        p2.add(jLabel3);        p2.add(jtf2);        p2.add(jLabel4);        p2.add(jtf3);        p2.add(jLabel5);        p2.add(jtf4);        p3.add(jbtSzfx);        p7.add(jbtTxfx);        p8.add(jbtBtfx);        p9.add(jbtQx);        p10.add(jLabel10);        p10.add(jLabel11);        p10.add(jLabel12);        p11.add(p3);        p11.add(p7);        p11.add(p8);        p11.add(p9);        p11.add(p10);        p4.add(p1,BorderLayout.NORTH);        p4.add(p2,BorderLayout.CENTER);        p5.add(p4,BorderLayout.NORTH);        p5.add(p11,BorderLayout.WEST);    //    p6.add(jtArea);        p5.add(p6,BorderLayout.CENTER);                container.add(jLabel6, BorderLayout.NORTH);        container.add(jLabel7, BorderLayout.SOUTH);        container.add(jLabel8, BorderLayout.WEST);        container.add(jLabel9, BorderLayout.EAST);        container.add(p5, BorderLayout.CENTER);                jbtSzfx.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                String str1 = jtf1.getText();                String str2 = jtf2.getText();                String str3 = jtf3.getText();                String str4 = jtf4.getText();                Class class1 = new Class(str1,str2,str3);                String str = class1.toString();                File file = new File(str);               if(file.exists()){                    try {                        double[] fsce = {0,0,0,0,0};                        scoreReport scRet = read(str);                        int value = scRet.getAmount();                        double[] fxscore = new double[value];                        Course[] course = scRet.getCourseName();                         double[][] score = scRet.getScore();                        double[] percent = {0,0,0,0,0};                        double max=0,min=0,averge=0,sum=0;                        int j = 0;                        for (int i = 0; i < course.length; i++) {                            if (course[i].getName().equals(str4)) {                                j = i;                                break;                            }                        }                        for(int i = 0; i < value; i++ ){                            fxscore[i] = score[j][i];                        }                        max = fxscore[0];                        min = fxscore[0];                        for(int i = 0; i < value; i++){                            if(fxscore[i]>max)                                max = fxscore[i];                            if(fxscore[i]<min)                                min = fxscore[i];                            if(fxscore[i]<60)                                fsce[0]++;                            else if(fxscore[i]<70)                                fsce[1]++;                            else if(fxscore[i]<80)                                fsce[2]++;                            else if(fxscore[i]<90)                                fsce[3]++;                            else if(fxscore[i]<101)                                fsce[4]++;                            sum = sum + fxscore[i];                        }                        for( int i = 0 ; i < 5 ; i++){                            percent[i] = (int)(fsce[i]/value*1000)/10.0;                        }                        averge = sum/value;                        String stringXs = "\n" + "\t               " + "数字分析结果" + "\n\n" + "      考试总人数:" + value +                                "   最高分:" + max + "   最低分:" + min + "   平均分: " + averge + "\n\n" +                                "\t   0-59  " + "      人数:" + fsce[0] + "   占:" + percent[0] +"%\n" +                                "\t   60-69  " + "    人数:" + fsce[1] + "   占:" + percent[1] +"%\n" +                                "\t   70-79  " + "    人数:" + fsce[2] + "   占:" + percent[2] +"%\n" +                                "\t   80-89  " + "    人数:" + fsce[3] + "   占:" + percent[3] +"%\n" +                                "\t   90-100  " + "  人数:" + fsce[4] + "   占:" + percent[4] +"%\n" ;                        jtArea.setText(stringXs);                         p6.removeAll();                        p6.add(jtArea,BorderLayout.CENTER);                        p6.updateUI();                    } catch (FileNotFoundException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    } catch (IOException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    } catch (ClassNotFoundException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    }               }            }        });                jbtTxfx.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                String str1 = jtf1.getText();                String str2 = jtf2.getText();                String str3 = jtf3.getText();                String str4 = jtf4.getText();                Class class1 = new Class(str1,str2,str3);                String str = class1.toString();                File file = new File(str);               if(file.exists()){                    try {                        int[] fsce = {0,0,0,0,0};                        scoreReport scRet = read(str);                        Student[] studentList = scRet.getStudentList();                        int value = scRet.getAmount();                        double[] fxscore = new double[value];                        Course[] course = scRet.getCourseName();                         double[][] score = scRet.getScore();                        int j = 0;                        for (int i = 0; i < course.length; i++) {                            if (course[i].getName().equals(str4)) {                                j = i;                                break;                            }                        }                        for(int i = 0; i < value; i++ ){                            fxscore[i] = score[j][i];                        }                        for(int i = 0; i < value; i++){                            if(fxscore[i]<60)                                fsce[0]++;                            else if(fxscore[i]<70)                                fsce[1]++;                            else if(fxscore[i]<80)                                fsce[2]++;                            else if(fxscore[i]<90)                                fsce[3]++;                            else if(fxscore[i]<101)                                fsce[4]++;                        }                 //       System.out.println(fsce[0] + " " + fsce[1] + " " + fsce[2]  + " " + fsce[3] + " " + fsce[4]);                        DrawRectangles1 DR = new DrawRectangles1(fsce);                        p6.removeAll();                        p6.add(DR,BorderLayout.CENTER);                        p6.updateUI();                    } catch (FileNotFoundException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    } catch (IOException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    } catch (ClassNotFoundException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    }               }            }        });                jbtBtfx.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                String str1 = jtf1.getText();                String str2 = jtf2.getText();                String str3 = jtf3.getText();                String str4 = jtf4.getText();                Class class1 = new Class(str1,str2,str3);                String str = class1.toString();                File file = new File(str);               if(file.exists()){                    try {                        int[] fsce = {0,0,0,0,0};                        scoreReport scRet = read(str);                        int value = scRet.getAmount();                        double[] fxscore = new double[value];                        Course[] course = scRet.getCourseName();                         double[][] score = scRet.getScore();                        int k = 0;                        for (int i = 0; i < course.length; i++) {                            if (course[i].getName().equals(str4)) {                                k = i;                                break;                            }                        }                        for(int i = 0; i < value; i++ ){                            fxscore[i] = score[k][i];                        }                        for(int i = 0; i < value; i++){                            if(fxscore[i]<60)                                fsce[0]++;                            else if(fxscore[i]<70)                                fsce[1]++;                            else if(fxscore[i]<80)                                fsce[2]++;                            else if(fxscore[i]<90)                                fsce[3]++;                            else if(fxscore[i]<101)                                fsce[4]++;                        }              //          System.out.println(fsce[0] + " " + fsce[1] + " " + fsce[2]  + " " + fsce[3] + " " + fsce[4]);                        int[] temp1 = new int[5];                        int[] temp2 = new int[5];                        for(int i=4,j=0;j<4&&i>0;i--,j++){                           temp1[j]=fsce[i]*360/value;                           temp2[j]=fsce[i]*1000/value;	                }                  	temp1[4]=360;	         	temp2[4]=1000;                        for(int j=0;j<4;j++){	        	temp1[4]=temp1[4]-temp1[j];	                temp2[4]=temp2[4]-temp2[j];                        }                        DrawFillOval1 DFO = new DrawFillOval1(temp1,temp2);                        p6.removeAll();                        p6.add(DFO,BorderLayout.CENTER);                        p6.updateUI();                    } catch (FileNotFoundException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    } catch (IOException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    } catch (ClassNotFoundException ex) {                        Logger.getLogger(ButtonListener4.class.getName()).log(Level.SEVERE, null, ex);                    }               }            }        });                jbtQx.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                frame1.dispose();            }        });    }   protected scoreReport read(String str) throws FileNotFoundException, IOException, ClassNotFoundException{            ObjectInputStream input = new ObjectInputStream(new BufferedInputStream(new FileInputStream(str)));            scoreReport scRet = (scoreReport) (input.readObject());            input.close();            return scRet;        }}

⌨️ 快捷键说明

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