学生管理系统

import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
//定义学生类的基本信息
class student
{
    //私有定义学生信息
    private String name;
    private String id;
    private String className;
    
    private int score_1;
    private int score_2;
    
    public String score1;
    public String score2;
    
    public void setName(String name)
    {
        this.name = name;
    }
    public String getName()
    {
        return name;
    }
    public void setId(String id)
    {
        this.id=id;
    }
    public String getId()
    {
        return id;
    }
    public void setClassName(String className)
    {
        this.className=className;
    }
    public String getClassName()
    {
        return className;
    }
    
    public void setScore_1(int score_1)
    {
        this.score_1=score_1;
    }
    public int getScore_1() 
    {
        return score_1;
    }
    public void setScore_2(int score_2)
    {
        this.score_2=score_2;
    }
    public int getScore_2() 
    {
        return score_2;
    }
}
//定义gui类框图显示
class gui{
    private Frame frame;//主界面
    private Button addButton,delectButton,changeButton,inspectButton,inspectAllButton,showButton;
    //主界面上的六个按键
     static student []stu = new student[100];//
     
     static int number=0;
     static int flag =0;//addButton里面的标志
     static int flag1=0;//changeButton里面的标志
     private MenuBar menuBar;
        private Menu menu;
        private MenuItem openItem,saveItem;
        private FileDialog openDialog,saveDialog;//打开和保存窗口
        private File file;
public  gui()
    {
        init();
    }
    public void init()
    {
        frame = new JFrame("学生管理系统");
        frame.setBounds(500, 200, 300, 400);
        frame.setLayout(new FlowLayout());
     menuBar = new MenuBar();
     menu = new Menu("菜单");
     
     openItem = new MenuItem("打开");
     saveItem = new MenuItem("保存");
    
     menu.add(openItem);
     menu.add(saveItem);
     menuBar.add(menu);
     frame.setMenuBar(menuBar);
        addButton = new Button("添加学生信息");
        delectButton = new Button("删除学生信息");
        changeButton = new Button("修改学生信息");
        inspectButton = new Button("查看某个学生信息");
        inspectAllButton = new Button("查看所有学生的信息");
        showButton = new Button("排名榜");
        frame.setLayout(new GridLayout(3,2,10,10));
        frame.add(addButton);
        frame.add(delectButton);
        frame.add(changeButton);
        frame.add(inspectButton);
        frame.add(inspectAllButton);
        frame.add(showButton);  
        myEvent();//事件函数
        frame.setVisible(true);
    }
    public void myEvent()//事件函数内容
    {
        //关闭窗体事件
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
        //保存文本事件
        saveItem.addActionListener(new ActionListener()
        {
              public void actionPerformed(ActionEvent e)
              {
                  saveDialog = new FileDialog(frame,"保存",FileDialog.SAVE);
                     if(file==null)
                      {
                      saveDialog.setVisible(true);
                      String fileName = saveDialog.getFile();
                      String directionName = saveDialog.getDirectory();
                      if(fileName == null || directionName == null)
                          return ;
                      file = new File(directionName,fileName);
                      }
                      try {
                        BufferedWriter bwr = new BufferedWriter(new FileWriter(file));
                        String text = "班级            姓名     学号         java成绩  电路设计成绩\r\n";
                        for(int i=0;i<number;i++)
                        {
                            text +=stu[i].getClassName()+"  "+stu[i].getName()+"  "+stu[i].getId()
                                    +"     "+stu[i].score1+"                "+stu[i].score2+"\r\n";
                        }
                        bwr.write(text);//写入
                        bwr.flush();
                        bwr.close();
                    } catch (FileNotFoundException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                    } catch (IOException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                    }
              }
        });
        //读取文本事件
        openItem.addActionListener(new ActionListener()
        {
              public void actionPerformed(ActionEvent e)
              {
                  openDialog = new FileDialog(frame,"读取文本",FileDialog.LOAD);
                  openDialog.setVisible(true);
                  String fileName = openDialog.getFile();
                  String directionName = openDialog.getDirectory();
                  if(fileName == null || directionName == null)
                      return ;
                  file = new File(directionName,fileName);
                  try {
                    BufferedReader buff = new BufferedReader(new FileReader(file));
                     String line = null;
                     String str="";
                    while((line=buff.readLine())!=null)
                    {
                        str +=line+" ";  
                    }
                    String[] s = str.split("\\s+");//很厉害的一种方法  以空格分割
                    buff.close();
                    for(int i=5;i<=s.length-1;i++)
                    if(i%5==0)
                    {
                        //将读到的值赋给变量
                        stu[i/5-1]=new student();
                        stu[i/5-1].setClassName(s[i]);
                        stu[i/5-1].setName(s[i+1]);
                        stu[i/5-1].setId(s[i+2]);
                        //stu[i/5].setScore_1(Integer.parseInt(s[i+3]));
                        //stu[i/5].setScore_2(Integer.parseInt(s[i+4]));
                        stu[i/5-1].score1=s[i+3];
                        stu[i/5-1].score2=s[i+4];
                    if(stu[i/5-1].score1.equals("未选"))//为了免除影响冠军榜的排名
                        {
                            stu[i/5-1].setScore_1(0);
                        }
                        else
                        {
                            stu[i/5-1].setScore_1(Integer.parseInt(stu[i/5-1].score1));
                        }
                        if(stu[i/5-1].score2.equals("未选"))
                        {
                            stu[i/5-1].setScore_2(0);
                        }
                        else
                        {
                            stu[i/5-1].setScore_2(Integer.parseInt(stu[i/5-1].score2));
                        }
                        number++;
                    }
                
                } catch (FileNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
              }
        });
        
        
        
        
        //添加学生信息事件
        addButton.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e)
            {
                flag =0;
                JFrame dialog = new JFrame("添加学生信息");
                JPanel jp1, jp2 ,jp3,jp4,jp5;
                dialog.setBounds(500, 200, 300, 400);
                dialog.setVisible(true);
                dialog.setLayout(new GridLayout(5,1));
                Label labelClassName = new Label("班级:");
                
                TextField text_1 = new TextField(20);
                jp1=new JPanel();
               jp1.add(labelClassName); jp1.add(text_1);
                Label labelName = new Label("姓名:");
                
                TextField text_2 = new TextField(20);
                jp2=new JPanel();
               jp2.add(labelName); jp2.add(text_2);
                Label labelId = new Label("学号:");
              
                TextField text_3 = new TextField(20);
                jp3=new JPanel();
              jp3.add(labelId); jp3.add(text_3);
              dialog.add(jp1); dialog.add(jp2); dialog.add(jp3);
              JButton button1 = new JButton("java语言程序设计成绩输入");
                JButton button2 = new JButton("电路设计成绩输入");
               jp4=new JPanel();
               jp4.add(button1); jp4.add(button2);
               dialog.add(jp4);
              
                JButton button3 = new JButton("继续输入");
                JButton button4 = new JButton("关闭");
                jp5=new JPanel();
                   jp5.add(button3); jp5.add(button4);
                   dialog.add(jp5);
                   //填写java成绩事件
                button1.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e)
                    {
                        //建立一个窗口填写java成绩
                        Dialog dia = new Dialog(dialog,"填写java成绩");
                        dia.setBounds(550, 250, 200, 300);
                        dia.setVisible(true);
                        //防止未填写学生基本信息
                        if((text_1.getText().isEmpty())||(text_2.getText().isEmpty())||(text_3.getText().isEmpty()))
                        {
                            dia.setVisible(false);
                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                    "学生基本信息未填写完整!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                            
                            
                        }
                        
                        dia.setLayout(new FlowLayout());
                        Label  la1 = new Label("平时成绩");
                        TextField  tf1 =new TextField(20);
                        TextField  tf2 =new TextField(20);
                        TextField  tf3 =new TextField(20);
                        TextField  tf4 =new TextField(20);
                        TextField  tf5 =new TextField(20);
                        Label  la2 = new Label("期末成绩");
                        TextField  tf6 =new TextField(20);
                        dia.add(la1);
                        dia.add(tf1);
                        dia.add(tf2);
                        dia.add(tf3);
                        dia.add(tf4);
                        dia.add(tf5);
                        dia.add(la2);
                        dia.add(tf6);
                        JButton btn = new JButton("保存");
                        dia.add(btn);
                        //保存之后事件
                        btn.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent e)
                            {
                                if((tf1.getText()!=null)&&(tf2.getText()!=null)&&(tf3.getText()!=null)&&(tf4.getText()!=null)
                                        &&(tf5.getText()!=null)&&(tf6.getText()!=null))
                                {
                                    int a = Integer.parseInt(tf1.getText());
                                    int b = Integer.parseInt(tf2.getText());
                                    int c = Integer.parseInt(tf3.getText());
                                    int d = Integer.parseInt(tf4.getText());
                                    int f = Integer.parseInt(tf5.getText());
                                    int g = Integer.parseInt(tf6.getText());
                                    int h= (int)((a+b+c+d+f)/5*0.8+g*0.2);
                                    //计算学生java成绩
                                    if(flag==0)
                                    {
                                        flag=1;
                                        stu[number] = new student();
                                        stu[number].setClassName(text_1.getText());
                                        stu[number].setName(text_2.getText());
                                        stu[number].setId(text_3.getText());
                                        stu[number].setScore_1(h);
                                        stu[number].score1=stu[number].getScore_1()+"";
                                        stu[number].score2="未选";//为防止没有电路设计课
                                        number++;
                                    }
                                    else
                                    {
                                        stu[number-1].setScore_1(h);
                                        stu[number-1].score1=stu[number-1].getScore_1()+"";
                                    }
                                    tf1.setText("");tf2.setText("");tf3.setText("");
                                    tf4.setText("");tf5.setText("");tf6.setText("");//清空
                                }
                                dia.dispose();//关闭窗口
                            }
                        });
                        dia.addWindowListener(new WindowAdapter() {
                            public void windowClosing(WindowEvent e)
                            {
                                dia.dispose();
                                
                            }
                        });
                    }
                });
                //填写电路设计成绩事件
                button2.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e)
                    {
                        Dialog dia = new Dialog(dialog,"填写电路设计成绩");
                        dia.setBounds(550, 250, 200, 300);
                        dia.setVisible(true);
                        //防止未填写学生基本信息
                        if((text_1.getText().isEmpty())||(text_2.getText().isEmpty())||(text_3.getText().isEmpty()))
                        {
                            dia.setVisible(false);
                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                    "学生基本信息未填写完整!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                            
                            
                        }
                        dia.setLayout(new FlowLayout());
                        Label  la1 = new Label("平时成绩");
                        TextField  tf1 =new TextField(20); 
                        Label  la2 = new Label("期末成绩");
                        TextField  tf2 =new TextField(20);
                        dia.add(la1);
                        dia.add(tf1);
                        dia.add(la2);
                        dia.add(tf2);
                        JButton btn = new JButton("保存");
                        dia.add(btn);
                        btn.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent e)
                            {
                                
                                if((tf1.getText()!=null)&&(tf2.getText()!=null))
                                {
                                    int a = Integer.parseInt(tf1.getText());
                                    int b = Integer.parseInt(tf2.getText());
                                    //得到学生成绩
                                    if(flag==0)
                                    {
                                        flag=1;
                                        stu[number] = new student();
                                        stu[number].setClassName(text_1.getText());
                                        stu[number].setName(text_2.getText());
                                        stu[number].setId(text_3.getText());
                                        stu[number].setScore_2((a+b)/2);
                                        stu[number].score2=stu[number].getScore_2()+"";
                                        stu[number].score1="未选";
                                        number++;
                                    }
                                    else
                                    {
                                        stu[number-1].setScore_2((a+b)/2);
                                        stu[number-1].score2=stu[number-1].getScore_2()+"";
                                    }
                                    tf1.setText("");
                                    tf2.setText("");
                                }
                                
                                dia.dispose();
                            }
                        });
                         
                        dia.addWindowListener(new WindowAdapter() {
                            public void windowClosing(WindowEvent e)
                            {
                                dia.dispose();
                                
                            }
                        });
                    }
                });
                button3.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e)
                    {
                        text_1.setText("");
                        text_2.setText("");
                        text_3.setText("");//清空学生基本信息
                        flag=0;//清除标志位
                    }
             });
             button4.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e)
                    {
                         
                        dialog.dispose();
                    }
             });
                dialog.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e)
                    {
                        dialog.dispose();
                        
                    }
                });
                
            }
        });
        //删除学生信息事件
        delectButton.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e)
            {
                String studentid=JOptionPane.showInputDialog("请输入你要删除的学生的学号:"); 
                int i,j=0;
                for(i=0;i<number;i++)
                {
                    if(studentid.equals(stu[i].getId()))
                    {
                        for(;i<number-1;i++)
                            stu[i]=stu[i+1];
                        number -= 1;
                        JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                "学生信息已删除!", "提示", JOptionPane.INFORMATION_MESSAGE);
                        j=1;
                        break;
                    }
                }
                if(i==number&&j==0)
                {
                    JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                            "该学生未找到!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                   j=0; 
                }
            }
                });
        //改变学生信息事件
                changeButton.addMouseListener(new MouseAdapter() {
                
                    public void mouseClicked(MouseEvent e)
                    {
                        String studentid=JOptionPane.showInputDialog("请输入你要修改学生的学号:"); 
                        int i;
                        for( i=0;i<number;i++)
                        {
                            if(studentid.equals(stu[i].getId()))
                            {
                                final int n =i;
                                flag1=0;
                                JFrame dialog = new JFrame("修改学生信息");
                                JPanel jp1, jp2 ,jp3,jp4;
                                dialog.setBounds(500, 200, 300, 400);
                                dialog.setVisible(true);
                                dialog.setLayout(new GridLayout(5,1));
                                Label labelClassName = new Label("班级:");
                                
                                TextField text_1 = new TextField(20);
                                jp1=new JPanel();
                               jp1.add(labelClassName); jp1.add(text_1);
                                Label labelName = new Label("姓名:");
                                
                                TextField text_2 = new TextField(20);
                                jp2=new JPanel();
                               jp2.add(labelName); jp2.add(text_2);
                                Label labelId = new Label("学号:");
                              
                                TextField text_3 = new TextField(20);
                                jp3=new JPanel();
                              jp3.add(labelId); jp3.add(text_3);
                              dialog.add(jp1); dialog.add(jp2); dialog.add(jp3);
                              JButton button1 = new JButton("java语言程序设计成绩输入");
                                JButton button2 = new JButton("电路设计成绩输入");
                               jp4=new JPanel();
                               jp4.add(button1); jp4.add(button2);
                               dialog.add(jp4);
                               
                                button1.addMouseListener(new MouseAdapter() {
                                    public void mouseClicked(MouseEvent e)
                                    {
                                        
                                        Dialog dia = new Dialog(dialog,"填写java成绩");
                                        dia.setBounds(550, 250, 200, 300);
                                        dia.setVisible(true);
                                        if((text_1.getText().isEmpty())||(text_2.getText().isEmpty())||(text_3.getText().isEmpty()))
                                        {
                                            dia.setVisible(false);
                                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                                    "学生基本信息未填写完整!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                                            
                                            
                                        }
                                        
                                        dia.setLayout(new FlowLayout());
                                        Label  la1 = new Label("平时成绩");
                                        TextField  tf1 =new TextField(20);
                                        TextField  tf2 =new TextField(20);
                                        TextField  tf3 =new TextField(20);
                                        TextField  tf4 =new TextField(20);
                                        TextField  tf5 =new TextField(20);
                                        Label  la2 = new Label("期末成绩");
                                        TextField  tf6 =new TextField(20);
                                        dia.add(la1);
                                        dia.add(tf1);
                                        dia.add(tf2);
                                        dia.add(tf3);
                                        dia.add(tf4);
                                        dia.add(tf5);
                                        dia.add(la2);
                                        dia.add(tf6);
                                        JButton btn = new JButton("保存");
                                        dia.add(btn);
                                        
                                        btn.addMouseListener(new MouseAdapter() {
                                            public void mouseClicked(MouseEvent e)
                                            {
                                                if((tf1.getText()!=null)&&(tf2.getText()!=null)&&(tf3.getText()!=null)&&(tf4.getText()!=null)
                                                        &&(tf5.getText()!=null)&&(tf6.getText()!=null))
                                                {
                                                    int a = Integer.parseInt(tf1.getText());
                                                    int b = Integer.parseInt(tf2.getText());
                                                    int c = Integer.parseInt(tf3.getText());
                                                    int d = Integer.parseInt(tf4.getText());
                                                    int f = Integer.parseInt(tf5.getText());
                                                    int g = Integer.parseInt(tf6.getText());
                                                    int h= (int)((a+b+c+d+f)/5*0.8+g*0.2);
                                                if(flag1==0) {      
                                                        flag1=1;
                                                        stu[n].setClassName(text_1.getText());
                                                        stu[n].setName(text_2.getText());
                                                        stu[n].setId(text_3.getText());
                                                        stu[n].score2="未选";
                                                        stu[n].setScore_1(h);
                                                        stu[n].score1=stu[n].getScore_1()+"";
                                                        
                                                    }
                                                    else
                                                    {
                                                        stu[n].setScore_1(h);
                                                        stu[n].score1=stu[n].getScore_1()+"";
                                                    }
                        
                                                }
                                                dia.dispose();
                                            }
                                        });
                                        dia.addWindowListener(new WindowAdapter() {
                                            public void windowClosing(WindowEvent e)
                                            {
                                                dia.dispose();
                                                
                                            }
                                        });
                                    }
                                });
                                button2.addMouseListener(new MouseAdapter() {
                                    public void mouseClicked(MouseEvent e)
                                    {
                                        Dialog dia = new Dialog(dialog,"填写电路设计成绩");
                                        dia.setBounds(550, 250, 200, 300);
                                        dia.setVisible(true);
                                        if((text_1.getText().isEmpty())||(text_2.getText().isEmpty())||(text_3.getText().isEmpty()))
                                        {
                                            dia.setVisible(false);
                                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                                    "学生基本信息未填写完整!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                                            
                                            
                                        }
                                        dia.setLayout(new FlowLayout());
                                        Label  la1 = new Label("平时成绩");
                                        TextField  tf1 =new TextField(20); 
                                        Label  la2 = new Label("期末成绩");
                                        TextField  tf2 =new TextField(20);
                                        dia.add(la1);
                                        dia.add(tf1);
                                        dia.add(la2);
                                        dia.add(tf2);
                                        JButton btn = new JButton("保存");
                                        dia.add(btn);
                                        btn.addMouseListener(new MouseAdapter() {
                                            public void mouseClicked(MouseEvent e)
                                            {
                                                
                                                if((tf1.getText()!=null)&&(tf2.getText()!=null))
                                                {
                                                    int a = Integer.parseInt(tf1.getText());
                                                    int b = Integer.parseInt(tf2.getText());
                                                    
                                                    if(flag1==0)
                                                    {
                                                        flag1=1;
                                                        stu[n] = new student();
                                                        stu[n].setClassName(text_1.getText());
                                                        stu[n].setName(text_2.getText());
                                                        stu[n].setId(text_3.getText());
                                                        stu[n].setScore_2((a+b)/2);
                                                        stu[n].score2=stu[n].getScore_2()+"";
                                                        stu[n].score2="未选";
                                                    
                                                    }
                                                    else
                                                    {
                                                        stu[n].setScore_2((a+b)/2);
                                                        stu[n].score2=stu[n].getScore_2()+"";
                                                    }
                                                
                                                }
                                                
                                                dia.dispose();
                                            }
                                        });
                                         
                                        dia.addWindowListener(new WindowAdapter() {
                                            public void windowClosing(WindowEvent e)
                                            {
                                                dia.dispose();
                                                
                                            }
                                        });
                                    }
                                });
                                
                                
                                break;
                            }
                        }
                        if(i==number)
                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                    "该学生未找到!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                        
                        
                    }
                });
                //查看某个学生信息事件
                inspectButton.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e)
                    {
                        String studentid=JOptionPane.showInputDialog("请输入你要查看的学生的学号:"); 
                        int i;
                        for( i=0;i<number;i++)
                        {
                            if(studentid.equals(stu[i].getId()))
                            {
                                String in = stu[i].getClassName()+"    "+stu[i].getName()+"     "+stu[i].getId()+"          "+stu[i].score1+"         "+stu[i].score2;
                                String out ="班级               姓名       学号              java成绩  电路成绩\n"+in;
                                JOptionPane.showMessageDialog(null,out); 
                                break;
                            }
                        }
                        if(i==number)
                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                    "该学生未找到!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                        
                    }
                });
                //查看所有学生信息事件
                inspectAllButton.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e)
                    {
                        Dialog dialog = new Dialog(frame,"查看所有学生的信息");
                        dialog.setBounds(500, 200, 450, 400);
                        dialog.setVisible(true);
                        if(number==0)
                        {
                            dialog.dispose();
                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                    "没有学生信息!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                            
                        }
                        
                        TextArea area = new TextArea();
                        dialog.add(area);
                        String in="";
                        for(int i=0;i<number;i++)
                        {
                             in   += stu[i].getClassName()+"    "+stu[i].getName()+"     "+stu[i].getId()+"          "+stu[i].score1+"         "+stu[i].score2+"\n";
                        }
                        String out ="班级        姓名       学号             java成绩  电路成绩\n"+in;
                        area.setText(out);
                        dialog.addWindowListener(new WindowAdapter() {
                            public void windowClosing(WindowEvent e)
                            {
                                dialog.dispose();
                            }
                        });
                        
                    }
                });
                //查看冠军榜事件
                showButton.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e)
                    {
                        Dialog dialog = new Dialog(frame,"排名榜");
                        dialog.setBounds(500, 200, 350, 400);
                        dialog.setVisible(true);
                        if(number==0)
                        {
                            dialog.dispose();
                            JOptionPane.showMessageDialog(new JFrame().getContentPane(), 
                                    "没有学生信息!", "提示", JOptionPane.INFORMATION_MESSAGE); 
                            
                        }
                        
                        TextArea area = new TextArea();
                        student s1 = new student();
                        student s2 = new student();
                        s1=stu[0];s2=stu[0];
                        for(int i=1;i<number;i++)
                        {
                            for(int j=0;j<number-i;j++)
                            {
                                if(stu[j].getScore_1()<stu[j+1].getScore_1())
                                {
                                    s1=stu[j];
                                    stu[j]=stu[j+1];
                                    stu[j+1]=s1;
                                }
                            }
                        }
                        String s="java语言程序设计排名\r\n";
                        for(int i=0;i<number;i++)
                        {
                            s +=stu[i].getName()+"  "+stu[i].getId()+"    "+stu[i].score1+"\r\n";
                        }
                        for(int i=1;i<number;i++)
                        {
                            for(int j=0;j<number-i;j++)
                            {
                                if(stu[j].getScore_2()<stu[j+1].getScore_2())
                                {
                                    s2=stu[j];
                                    stu[j]=stu[j+1];
                                    stu[j+1]=s2;
                                }
                            }
                        }
                        String stri = "电子设计排名\r\n";
                        for(int i=0;i<number;i++)
                        {
                            stri +=stu[i].getName()+"  "+stu[i].getId()+"    "+stu[i].score2+"\r\n";
                        }                       
                        area.setText(s+stri);
                        dialog.add(area);
                        dialog.addWindowListener(new WindowAdapter() {
                            public void windowClosing(WindowEvent e)
                            {
                                dialog.dispose();
                            }
                        });
                        
                    }
                });
            
    }
}
//主函数
public class work {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new gui();
          
    }

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,014评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,796评论 3 386
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,484评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,830评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,946评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,114评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,182评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,927评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,369评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,678评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,832评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,533评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,166评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,885评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,128评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,659评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,738评论 2 351

推荐阅读更多精彩内容