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

📄 inquest.java

📁 ——学生信息系统的设计与实现—— 以学生信息为背景
💻 JAVA
字号:
package student;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;


public class Inquest extends JDialog implements ActionListener

{ 

  int i; 
  
 public  static boolean s;
  
  JTextField 学号,姓名,专业,班级,年龄;                 

  JRadioButton 男,女;

  JButton 查询1,查询2,查询3;

  ButtonGroup group=null;

  FileInputStream inOne=null;

  ObjectInputStream inTwo=null;
  
  Lianbiao 基本信息[]=new Lianbiao[100];  
  
  public  static Lianbiao 基本信息1[]=new Lianbiao[100];

  File file=null;                                           

  public Inquest(JFrame f,File file)

  {

   super(f,"查询对话框",false); 
   
           for(i=0;i<100;i++)
         {    

           基本信息1[i]=new Lianbiao();
     
          }
   
     for(i=0;i<100;i++)
     {    

          基本信息[i]=new Lianbiao();
     
     }

   this.file=file;

   学号=new JTextField(10);

   查询1=new JButton("查询");

   学号.addActionListener(this);

   查询1.addActionListener(this);

   姓名=new JTextField(10);
   
   查询2=new JButton("查询");

   姓名.addActionListener(this);
   
   查询2.addActionListener(this);
   
      查询3=new JButton("查询");
      
      查询3.addActionListener(this);

   专业=new JTextField(10);

   专业.setEditable(false);

   班级=new JTextField(10);

   班级.setEditable(false);

   年龄=new JTextField(10);

   年龄.setEditable(false);

   男=new JRadioButton("男",false);

   女=new JRadioButton("女",false);

   group=new ButtonGroup();

   group.add(男);

   group.add(女);

   Box box1=Box.createHorizontalBox();              

   box1.add(new JLabel("输入要查询的学号:",JLabel.CENTER));

   box1.add(学号);

   box1.add(查询1);
   
   Box box2=Box.createHorizontalBox();
   
   box2.add(new JLabel("输入要查询的姓名:",JLabel.CENTER));


   box2.add(姓名);
   
   box2.add(查询2);
   
    Box box3=Box.createHorizontalBox();
   
    box3.add(new JLabel("输入要查询的姓名和学号:",JLabel.CENTER));

   
    box3.add(查询3);

   Box box4=Box.createHorizontalBox();              

   box4.add(new JLabel("性别:",JLabel.CENTER));

   box4.add(男);

   box4.add(女);

   Box box5=Box.createHorizontalBox();              

   box5.add(new JLabel("专业:",JLabel.CENTER));

   box5.add(专业);

   Box box6=Box.createHorizontalBox();              

   box6.add(new JLabel("班级:",JLabel.CENTER));

   box6.add(班级);

   Box box7=Box.createHorizontalBox();              

   box7.add(new JLabel("年龄:",JLabel.CENTER));

   box7.add(年龄);

   Box boxH=Box.createVerticalBox();              

   boxH.add(box1);

   boxH.add(box2);

   boxH.add(box3);

   boxH.add(box4);

   boxH.add(box5);

   boxH.add(box6);

   boxH.add(Box.createVerticalGlue());          

   JPanel pCenter=new JPanel();

   pCenter.add(boxH);

   Container con=getContentPane();

   con.add(pCenter,BorderLayout.CENTER);

   con.validate();

   setVisible(false);

   setBounds(100,200,360,270);

   addWindowListener(new WindowAdapter()

                    { public void windowClosing(WindowEvent e)

                       {

                         setVisible(false);

                         }

                    });

  }

 public void actionPerformed(ActionEvent e)

  {    

     专业.setText(null);

     班级.setText(null);

     年龄.setText(null);

     

    if(e.getSource()==查询1||e.getSource()==学号)

      {

         String number="";

         number=学号.getText();

        

         if(number.length()>0)

            {

              try {

                    inOne=new FileInputStream(file);

                    inTwo=new ObjectInputStream(inOne);

                    基本信息=(Lianbiao[])inTwo.readObject();

                    inOne.close();

                    inTwo.close();

                  }

               catch(Exception ee)

                   {

                   }

               if(Lianbiao.cn(number))        

                 {

                   String warning="学号必须全为数字!";

                    

                   JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }

                else if(Lianbiao.a(基本信息,number))                

                 {

                  Student 学生=new Student(); 

                  Lianbiao.lim(基本信息,学生,number);

                   姓名.setText(学生.getName());

                   专业.setText(学生.getDisciping());

                   班级.setText(学生.getJclass());

                   年龄.setText(学生.getAge()); 

                   if(学生.getSex().equals("男"))

                      {

                        男.setSelected(true);

                      }

                    else

                      {

                        女.setSelected(true);

                      }

   

                 }

              else

                 { 

                  String warning="该学号不存在!";

                  JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }

            }

        else

            { 

              String warning="必须要输入学号!";

              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

            }

      }
     
         if(e.getSource()==查询3||e.getSource()==学号||e.getSource()==姓名)

      {

         String number="";

         number=学号.getText();

         String name="";

         name=姓名.getText();

         if(number.length()>0&&name.length()>0)

            {

              try {

                    inOne=new FileInputStream(file);

                    inTwo=new ObjectInputStream(inOne);

                    基本信息=(Lianbiao[])inTwo.readObject();

                    inOne.close();

                    inTwo.close();

                  }

               catch(Exception ee)

                   {

                   }

               if(Lianbiao.cn(number))        

                 {

                   String warning="学号必须全为数字!";

                    

                   JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }

                else    if(Lianbiao.ca(name))        

                 {

                   String warning="姓名必须全为字母!";

                    

                   JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }
                else  if(Lianbiao.c(基本信息,number,name))                

                 {

                  Student 学生=new Student(); 

                  Lianbiao.lim(基本信息,学生,number);

                   姓名.setText(学生.getName());

                   专业.setText(学生.getDisciping());

                   班级.setText(学生.getJclass());

                   年龄.setText(学生.getAge()); 

                   if(学生.getSex().equals("男"))

                      {

                        男.setSelected(true);

                      }

                    else

                      {

                        女.setSelected(true);

                      }

   

                 }

              else

                 { 
                  
                  String warning=" ";
                  if(!Lianbiao.a(基本信息,number)){
                   warning="该学号不存在!";
                  }
                  
                  else   if(!Lianbiao.b(基本信息,name)){
                   warning="该姓名不存在!";
                  }
                  
                  else if(!Lianbiao.c(基本信息,number,name)){
                   warning="该学号与姓名不符合!";
                  } 

                  JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }

            }

        else

            { 

              String warning="必须要输入学号和姓名!";

              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

            }

      }
     
         if(e.getSource()==查询2||e.getSource()==姓名)

      {

         String name="";

         name=姓名.getText();

        

         if(name.length()>0)

            {

              try {

                    inOne=new FileInputStream(file);

                    inTwo=new ObjectInputStream(inOne);

                   基本信息=(Lianbiao[])inTwo.readObject();

                    inOne.close();

                    inTwo.close();

                  }

               catch(Exception ee)

                   {

                   }
              
                 基本信息1=基本信息.clone()  ;

                 if(Lianbiao.ca(name))        

                 {

                   String warning="姓名必须全为字母!";

                    

                   JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }
              else if(Lianbiao.b(基本信息1,name))         

                 {
               Lianbiao.pa(基本信息1);
               
               s=true;
               
               new ColumnModelTest(); 
                        
                  }
              else

                 { 

                  String warning="该姓名不存在!";

                  JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }

            }

        else

            { 

              String warning="必须要输入姓名!";

              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

            }

      }

  }
 
     public static  Lianbiao[] GetL()
    {
        return 基本信息1;
    }
    
         public static  boolean  GetS()
    {
         return s;
    }  
}


⌨️ 快捷键说明

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