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

📄 stusearchframe.java

📁 辽宁交通专科学校03级大三的一个课程设计学生成绩管理信息系统.赵磊
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.table.*;
class StusearchFrame extends JFrame  implements ActionListener
{ String strSQL="adnid";
 // String str="adnid";
  JFrame f=new JFrame("学生信息选择查询  ");
  JRadioButton rbtnid=new JRadioButton("学号 "),
               rbtnname=new JRadioButton("姓名 "),
               rbtnsex=new JRadioButton("性别 "), 
               rbtnbirth=new JRadioButton("生日 "),
               rbtnmajor=new JRadioButton("专业 "),
               rbtnphone=new JRadioButton(" 电话"),
               rbtnjiguan=new JRadioButton(" 籍贯");
  JLabel lbtj=new JLabel("请选择查询的条件 "),
         lbshuru=new JLabel("请输入查询的内容 ");
  JButton btnserch=new JButton("查询 ");
  JButton btnexit=new JButton("退出 ");
  ButtonGroup bgp=new ButtonGroup();
  JPanel p=new JPanel(),
         p1=new JPanel(),
         p2=new JPanel();
  JTextField tfshuru=new JTextField(25); 
  
  ////////////////////
  JScrollPane sp=new JScrollPane();
  Vector tempvector1;
  DefaultTableModel model=new DefaultTableModel();
  JTable TableResult=new JTable(model);
   
  public StusearchFrame()
  
 { Container cp=f.getContentPane();
   cp.setLayout(new BorderLayout());
   p.setLayout(new GridLayout(2,1));
   
   p1.add(lbtj);
   p1.add(rbtnid);p1.add(rbtnname);
   p1.add(rbtnsex);p1.add(rbtnbirth);p1.add(rbtnmajor);
   p1.add(rbtnphone);p1.add(rbtnjiguan);
   
   bgp.add(rbtnid);bgp.add(rbtnname);
   bgp.add(rbtnsex);bgp.add(rbtnbirth);bgp.add(rbtnmajor);
   bgp.add(rbtnphone);bgp.add(rbtnjiguan);
   
   p2.add(lbshuru);p2.add(tfshuru);p2.add(btnserch);p2.add(btnexit);
   p.add(p1);p.add(p2);
    rbtnid.addActionListener(this);
    rbtnname.addActionListener(this);
    rbtnsex.addActionListener(this);
    rbtnbirth.addActionListener(this);
    rbtnmajor.addActionListener(this);
    rbtnphone.addActionListener(this);
    rbtnjiguan.addActionListener(this);
    btnserch.addActionListener(this);
    btnexit.addActionListener(this);
   
   
    model.addColumn("学号") ;
    model.addColumn("姓名") ;
    model.addColumn("性别") ;
    model.addColumn("生日") ;
    model.addColumn("专业") ;
    model.addColumn("电话") ;
    model.addColumn("籍贯") ;
    sp.setSize(50,50);
    sp.getViewport().add(TableResult,null);
    
   cp.add("North",p);
   cp.add("South",sp);
   f.setSize(650,540);
   f.setVisible(true);
   }
   
   public void actionPerformed(ActionEvent e)
    {
     /*if (e.getSource()==rbtnid   )      {strSQL="select * from stuinfor where id";}
     if (e.getSource()==rbtnname  )     {strSQL="select * from stuinfor where name";}
     if (e.getSource()==rbtnsex )      {strSQL="select * from stuinfor where sex";}
     if (e.getSource()==rbtnbirth )    { strSQL="select * from stuinfor where birth";}
     if (e.getSource()==rbtnmajor  )     {strSQL="select * from stuinfor where major";}
     if (e.getSource()==rbtnphone  )      {strSQL="select * from stuinfor where phone";}
     if (e.getSource()==rbtnjiguan  )    { strSQL="select * from stuinfor where jiguan";}
    */	
    
     /*if(e.getSource()==rbtnid) {str="id";}
     if(e.getSource()==rbtnname) {str="name";}
     if(e.getSource()==rbtnsex) {str="sex";}
     if(e.getSource()==rbtnbirth){ str="birth";}
     if(e.getSource()==rbtnmajor) {str="major";}
     if(e.getSource()==rbtnphone) {str="phone";}
     if(e.getSource()==rbtnjiguan){ str="jiguan";}
    */
   
     if(e.getSource()==btnexit) {f.setVisible(false);}
     if(e.getSource()==btnserch)
     {  
     	
     	if(!tfshuru.getText().trim().equals(""))
     	{
     	  if(rbtnid.isSelected())
           strSQL="select * from stuinfor where id='"+tfshuru.getText().trim()+"'";
          else if(rbtnname.isSelected())
           strSQL="select * from stuinfor where name='"+tfshuru.getText().trim()+"'";
          else if(rbtnsex.isSelected())
           strSQL="select * from stuinfor where sex='"+tfshuru.getText().trim()+"'";
          else if(rbtnbirth.isSelected())
           strSQL="select * from stuinfor where birth='"+tfshuru.getText().trim()+"'";
          else if(rbtnmajor.isSelected())
           strSQL="select * from stuinfor where major='"+tfshuru.getText().trim()+"'";
          else if(rbtnphone.isSelected())
           strSQL="select * from stuinfor where phone='"+tfshuru.getText().trim()+"'";
          else if(rbtnjiguan.isSelected())
           strSQL="select * from stuinfor where jiguan='"+tfshuru.getText().trim()+"'";
          else  
          {JOptionPane.showMessageDialog(this,"抱歉,您还没有选择查询的条件,请选择查询的条件后再进行查询 ");
           tfshuru.setText(null);
          }
        }
        else JOptionPane.showMessageDialog(this,"抱歉,您还没有输入查询的内容,请输入查询的内容后再查询 ");
   
      	 for(int i=model.getRowCount()-1;i>=0;i--)
         { model.removeRow(i); }
	  	      	
     	      try{
	          Connection con=DriverManager.getConnection("jdbc:odbc:Xsstudent");
                  Statement s=con.createStatement();
                  //System.out.println(strSQL);
                  // System.out.println(str);
                  //String strSQL="select * from stuinfor where id='"+tfshuru.getText()+"'";
                         ResultSet rs=s.executeQuery(strSQL);
                         //boolean exist=rs.next();
                          if(!rs.next())
                          { JOptionPane.showMessageDialog(this,"抱歉,还没有您要查询的记录,或者您的输入不符合查询的条件,请确认后重新输入 ");
                            tfshuru.setText(null);
                          }
                           
                          else{
                            
		             do  {
		                System.out.println(strSQL);
			 	tempvector1=new Vector(1,1);
		         	tempvector1.add(rs.getString("id"));
			 	tempvector1.add(rs.getString("name"));
           	         	tempvector1.add(rs.getString("sex"));
			 	tempvector1.add(rs.getString("birth"));
			 	tempvector1.add(rs.getString("major"));
			 	tempvector1.add(rs.getString("phone"));
			 	tempvector1.add(rs.getString("jiguan"));
                                model.addRow(tempvector1);
     	                       }while(rs.next());
     	                   }
     	      
     	         s.close();
     	         con.close();       
     	         }       
     	      catch(Exception ee)
     	      {System.out.println("信息查询出错: "+ee.getMessage()); }
       }
     }
 
   public static void main(String args[])
     {          new StusearchFrame();
              String JDriver="sun.jdbc.odbc.JdbcOdbcDriver";
	      String conURL="jdbc:odbc:Xsstudent";
	      try
	      {
	      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	      }
	      catch(Exception e)
	      {System.out.println("加载驱动失败");}
  
     }                    
                 
}

⌨️ 快捷键说明

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