search_1.java

来自「学籍管理系统:利用JAVA的界面对MS SQL进行操作,实现了学生学籍管理系统基」· Java 代码 · 共 422 行

JAVA
422
字号
package E4;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.io.File;
import java.io.*;
import java.util.StringTokenizer;
import javax.swing.table.*;
import java.sql.*;

 //显示信息
class Search_1 implements ActionListener
 { 

    JDialog jfm; 
     

    JTabbedPane jplForFrame=new JTabbedPane(); 
        
    JLabel tell=new JLabel("查找学籍信息",JLabel.CENTER);
    
    panelForSearchId_1 pfsi;
    panelForSearchName_1 pfsn;
    panelForSearchClass_1 pfscla;
    panelForSearchCollege_1 pfsco;
    panelForSearchNation_1 pfsnation;
    
   Search_1(JFrame f,String s,boolean b)
   {
   	
  

   	jfm=new JDialog(f,s,b);
    jfm.setSize(450,220);
    
    jfm.setBackground(Color.white);
    pfsi= new panelForSearchId_1(f,b);
    pfsn= new panelForSearchName_1(f,b);
    pfscla= new panelForSearchClass_1(f,b);
    pfsco= new panelForSearchCollege_1(f,b);
    pfsnation= new panelForSearchNation_1(f,b);
    
    jfm.addWindowListener(new WindowAdapter()
      {public void windowClosing(WindowEvent e)
       {
         jfm.setVisible(false);
       }});
    jfm.setResizable(false);
 
    jplForFrame.setBackground(Color.white);
    jplForFrame.addTab("按学号查找",pfsi);
    jplForFrame.addTab("按姓名查找",pfsn);
    jplForFrame.addTab("按院系查找",pfscla);
    jplForFrame.addTab("按班级查找",pfsco);
    jplForFrame.addTab("按民族查找",pfsnation);
    
    pfsi.cancel.addActionListener(this);
    pfsn.cancel.addActionListener(this);
    pfscla.cancel.addActionListener(this);
    pfsco.cancel.addActionListener(this);
    pfsnation.cancel.addActionListener(this);
    
    
    jfm.setLayout(new BorderLayout(9,9));
    jfm.add(jplForFrame);
    tell.setBackground(Color.BLACK);   
    jfm.add(tell,BorderLayout.NORTH);
   

   }
   
   public void actionPerformed(ActionEvent e){
      if(e.getSource()==pfsi.cancel){
      	this.setDisplay(false);
      }
     else  if(e.getSource()==pfsn.cancel){
      	this.setDisplay(false);
      }
     else if(e.getSource()==pfscla.cancel){
      	this.setDisplay(false);
      }
     else  if(e.getSource()==pfsco.cancel){
      	this.setDisplay(false);
      }
     else if(e.getSource()==pfsnation.cancel){
      	this.setDisplay(false);
      }
   	}
   

    public void setDisplay(Boolean tf){
   	jfm.setVisible(tf);
   }
   	
}

class panelForSearchId_1 extends JPanel implements ActionListener
{
	 //   framForSearch ffs;//查找界面
	JPanel contentPane_1,contentPane_3;
    
    JLabel du_id=new JLabel("输入学号",JLabel.CENTER); 
    JTextField jf_id=new JTextField("",8);  

	JButton handin = new JButton("提交");
	JButton cancel = new JButton("退出");
	
	proceeSQL psql=new proceeSQL();
    
   panelForSearchId_1(JFrame f,boolean b){

    //	ffs = new framForSearch(f,"查找用户信息",b);

    	contentPane_1=new JPanel();
    	contentPane_3=new JPanel();
    	
    	contentPane_1.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
    	contentPane_1.add(du_id);
    	contentPane_1.add(jf_id);  	

	    
	   contentPane_3.setLayout(new FlowLayout(FlowLayout.CENTER));
	   contentPane_3.add(handin);
	   contentPane_3.add(cancel);

	   cancel.addActionListener(this);
	    
	    super.setLayout(new BorderLayout(9,9));
	    super.add(new JLabel("按学号查找",JLabel.CENTER),BorderLayout.NORTH);
	    super.add(contentPane_1);
	    super.add(contentPane_3,BorderLayout.SOUTH);;
    	
    }
    

    
     public void actionPerformed(ActionEvent e){
     	
     	if(e.getSource()==cancel){
     
     	}
     	    	
    }
 }
 
 class panelForSearchName_1 extends JPanel implements ActionListener
{
	 //   framForSearch ffs;//查找界面
	JPanel contentPane_1,contentPane_3;
    
    JLabel du_id=new JLabel("输入姓名",JLabel.CENTER); 
    JTextField jf_id=new JTextField("",8);  

	JButton handin = new JButton("提交");
	JButton find =new JButton("查找");
	JButton cancel = new JButton("退出");
	
	proceeSQL psql=new proceeSQL();
    
   panelForSearchName_1(JFrame f,boolean b){

    	contentPane_1=new JPanel();
    	contentPane_3=new JPanel();
    	
    	contentPane_1.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
    	contentPane_1.add(du_id);
    	contentPane_1.add(jf_id);  	
    
	   contentPane_3.setLayout(new FlowLayout(FlowLayout.CENTER));
	   contentPane_3.add(handin);
	   contentPane_3.add(cancel);

	    cancel.addActionListener(this);
	    
	    super.setLayout(new BorderLayout(9,9));
	    super.add(new JLabel("按姓名查找",JLabel.CENTER),BorderLayout.NORTH);
	    super.add(contentPane_1);
	    super.add(contentPane_3,BorderLayout.SOUTH);;
    	
    }
    
     public void actionPerformed(ActionEvent e){
     	
     	if(e.getSource()==cancel){
     
     	}
     	    	
    }
 }


class panelForSearchClass_1 extends JPanel implements ActionListener,ItemListener
{
	 //   framForSearch ffs;//查找界面
	JPanel contentPane_1,contentPane_3;
    
    Choice college = new Choice();
    Choice classes = new Choice();

	JButton handin = new JButton("提交");
	JButton cancel = new JButton("退出");
	
	proceeSQL psql=new proceeSQL();
    
   panelForSearchClass_1(JFrame f,boolean b){

    //	ffs = new framForSearch(f,"查找用户信息",b);

    	contentPane_1=new JPanel();
    	contentPane_3=new JPanel();
    //计算机科学与技术,网络工程,软件工程,会计学,国际贸易,光电子,机械自动化,环境工程	
    	college.addItem("计算机科学与技术");
    	college.addItem("网络工程");
    	college.addItem("软件工程");
    	college.addItem("会计学");
    	college.addItem("国际贸易");
    	college.addItem("光电子");
    	college.addItem("机械自动化");
    	college.addItem("环境工程");

    	for(int i=3;i<7;i++)
    	  for(int j=0;j<4;j++)
    	    classes.addItem("计算机科学与技术0"+i+(j+1)+"班");
    	
    	contentPane_1.add(new JLabel("选择院系:",JLabel.CENTER));
    	contentPane_1.add(college);
    	contentPane_1.add(new JLabel("选择班级:",JLabel.CENTER));  	
    	contentPane_1.add(classes);

    	contentPane_1.setLayout(new GridLayout(2,2,9,9));
        
        college.addItemListener(this);
       // classes.addItemListener(this);
    	
	   contentPane_3.setLayout(new FlowLayout(FlowLayout.CENTER));
	   contentPane_3.add(handin);
	   contentPane_3.add(cancel);
	    
	    //handin.addActionListener(this);
	    cancel.addActionListener(this);
	    
	    super.setLayout(new BorderLayout(9,9));
	    super.add(new JLabel("按班级查找",JLabel.CENTER),BorderLayout.NORTH);
	    super.add(contentPane_1);
	    super.add(contentPane_3,BorderLayout.SOUTH);;
    	
    }
    
  void addIntoClasses(String college){
  	   classes.removeAll();
  	  	for(int i=3;i<7;i++)
    	  for(int j=0;j<4;j++)
    	    classes.addItem(college+"0"+i+(j+1)+"班");
  }
    
    
   public void itemStateChanged(ItemEvent e){
	 	
   	 	if(e.getItemSelectable()==college){
   	 		addIntoClasses(college.getSelectedItem());
   	 	}
   	 	
   	 	else if(e.getItemSelectable()==classes){
   	 		
   	 	}
   	 	
   	 }
    
     public void actionPerformed(ActionEvent e){
     	
     	if(e.getSource()==cancel){
           
     	}
     	
        else if(e.getSource()==handin){
        	  psql.DistroyStuInforByClasses(classes.getSelectedItem());	 	
     	}
    }
 }


class panelForSearchCollege_1 extends JPanel implements ActionListener,ItemListener
{

	 //   framForSearch ffs;//查找界面
	JPanel contentPane_1,contentPane_3;
    Choice college = new Choice();
 

	JButton handin = new JButton("提交");
	JButton cancel = new JButton("退出");
	
	proceeSQL psql=new proceeSQL();
    
   panelForSearchCollege_1(JFrame f,boolean b){

    //	ffs = new framForSearch(f,"查找用户信息",b);

    	contentPane_1=new JPanel();
    	contentPane_3=new JPanel();
    	          
      	college.addItem("计算机科学与技术");
    	college.addItem("网络工程");
    	college.addItem("软件工程");
    	college.addItem("会计学");
    	college.addItem("国际贸易");
    	college.addItem("光电子");
    	college.addItem("机械自动化");
    	college.addItem("环境工程");
       
       	contentPane_1.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
       	contentPane_1.add(new JLabel("选择院系:",JLabel.CENTER));
    	contentPane_1.add(college);  	
	    
	    college.addItemListener(this);
	    	
	    contentPane_3.setLayout(new FlowLayout(FlowLayout.CENTER));
	    contentPane_3.add(handin);
	    contentPane_3.add(cancel); 
	    
	   // handin.addActionListener(this);
	    cancel.addActionListener(this);
	    
	    super.setLayout(new BorderLayout(9,9));
	    super.add(new JLabel("按院系删除学生学籍",JLabel.CENTER),BorderLayout.NORTH);
	    super.add(contentPane_1);
	    super.add(contentPane_3,BorderLayout.SOUTH);;
    	
    }
    
    public void itemStateChanged(ItemEvent e){
	 	
   	 	if(e.getItemSelectable()==college){
   	 		
   	 	}
   	 	   	 	
   	 }
    
     public void actionPerformed(ActionEvent e){
     	
     	if(e.getSource()==cancel){
  
     	}
     	      	
        else if(e.getSource()==handin){
          psql.DistroyStuInforByCollege(college.getSelectedItem());
     	}      	
   	 	
     	}
    }
  
 


class panelForSearchNation_1 extends JPanel implements ActionListener
{
	 //   framForSearch ffs;//查找界面
	JPanel contentPane_1,contentPane_3;
    

	JButton handin = new JButton("提交");	
	JButton cancel = new JButton("退出");
	JTextField nation = new JTextField("",8);
	JButton find =new JButton("选择民族");
	String tempNation="";
	proceeSQL psql=new proceeSQL();
     Nation two ;
    
   panelForSearchNation_1(JFrame f,boolean b){
   	
    	contentPane_1=new JPanel();
    	contentPane_3=new JPanel();
    	
    	two = new Nation(f,"选择民族",false); 
    	
    	contentPane_3.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
    	contentPane_3.add(new JLabel("民族:",JLabel.CENTER));
    	contentPane_3.add(nation);  	
    	contentPane_3.add(find);
    	
        contentPane_1.setLayout(new FlowLayout(FlowLayout.CENTER));
	     contentPane_1.add(handin);
	     contentPane_1.add(cancel);
       
        find.addActionListener(this); 	    
	    handin.addActionListener(this);
	    cancel.addActionListener(this);
	    two.confirm.addActionListener(this);
	    
	    super.setLayout(new BorderLayout(9,9));
	    super.add(new JLabel("按民族查找学籍信息",JLabel.CENTER),BorderLayout.NORTH);
	    super.add(contentPane_3);
	    super.add(contentPane_1,BorderLayout.SOUTH);;
    	
    }
    
     public void actionPerformed(ActionEvent e){
     	
     	if(e.getSource()==cancel){
  
     	}
     	
     	else if(e.getSource()==find){
     		two.setDisplay(true);
     	}
     	 
     	else if(e.getSource()==two.confirm){
     		nation.setText(two.returnNation());
     		two.setDisplay(false);
     	}
     	    	
        else if(e.getSource()==handin){
         //psql.DistroyAllStuInfor();   	
   	 	
     	}
    }
 }


⌨️ 快捷键说明

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