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

📄 statist.java

📁 学生学籍管理系统
💻 JAVA
字号:
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 Statist extends JPanel implements ActionListener,TextListener,ItemListener
 { 
   public  JTable table;
   String  jname[]={"序号","登陆帐号","姓名","性别","年龄","寝室楼","房间号","邮政编码","电话号码","家庭地址","登陆密码"};	
   AbstractTableModel tm;  	
   Object StudentDetail[]=new Object[10];
   public Vector content = new Vector(); 
   int jishu;
    
    JLabel showNum=new JLabel("人数为:"+jishu);
    
    
    JPanel pnl;
    JPanel forAddNorth = new JPanel();
    JPanel forAddCenter = new JPanel();
    JPanel forAddSouth = new JPanel();
    Choice choice;
    Choice domBuilding;
    JRadioButton jrb_male=new JRadioButton("男");
    JRadioButton jrb_female=new JRadioButton("女");    
    ButtonGroup sex= new ButtonGroup();
    TextField name,id,postNum,domNum,homeAddress,telNum;
   	JPasswordField newPasswordField =new JPasswordField();//新密码
	JPasswordField confirmNewPasswordField =new JPasswordField();//确认新密码
    
    JButton confirm = new JButton("确定");//只有在单个学生时才好使
    JButton concel = new JButton("取消");
    
    
    JPanel jpl=new JPanel();
    JButton jFind=new JButton("查找");
    JButton jRefresh=new JButton("刷新");
      

    framForCompositor ffc;//排序界面
    SearchForStuDetail sfd;//查找界面
    proceeSQL psql;
    
   Statist(JFrame f,String s,boolean b)
   {
   	
   
   //	super(f);

   	sfd = new SearchForStuDetail(f,"查找",b);

   	psql = new proceeSQL();
   	
    //setSize(800,450);
    super.setVisible(true);
    super.setLayout(new BorderLayout(9,9));
     
    jishu = psql.SearchStudentDetail(content);
    
    showNum.setText("人数为:"+jishu);
     
    tm = new AbstractTableModel(){
     	  public String getColumnName(int col){return jname[col];   
          }   
    
          public int getColumnCount(){return jname.length;}   
    
          public int getRowCount(){return  content.size();}       
          public Object getValueAt(int row,int col){return ((Vector)content.get(row)).get(col);}   
     };	
     
    table=new JTable(tm);
   
     choice = new Choice();
       for(int i=10;i<30;i++)
         choice.addItem(""+i);
      
         
      domBuilding = new Choice();
      for(int i=0;i<10;i++)
       domBuilding.addItem(""+(i+1));
          
     name=new TextField("",8);
     id=new TextField("",8);
     postNum=new TextField("",8);
     domNum = new TextField("",8);
     homeAddress=new TextField("",8);
     telNum=new TextField("",8);

     pnl=new JPanel();
     

     sex.add(jrb_male);
     sex.add(jrb_female);
     pnl.add(jrb_male);
     pnl.add(jrb_female);
     choice.addItemListener(this);


     
    jpl=new JPanel(); 



    jpl.add(jFind);

    jpl.add(jRefresh);
    jpl.add(showNum);
    jpl.setLayout(new GridLayout(9,1,2,9));
    
    
     forAddNorth.add(new JLabel("帐号",JLabel.CENTER));
     forAddNorth.add(id);
     forAddNorth.add(new JLabel("姓名",JLabel.CENTER));
     forAddNorth.add(name);
     forAddNorth.add(new JLabel("姓别",JLabel.CENTER));
     forAddNorth.add(pnl);
     forAddNorth.add(new JLabel("年龄",JLabel.CENTER));
     forAddNorth.add(choice);
     forAddNorth.add(new JLabel("寝室楼",JLabel.CENTER));
     forAddNorth.add(domBuilding);
     forAddNorth.add(new JLabel("房间号",JLabel.CENTER));
     forAddNorth.add(domNum);
     forAddNorth.add(new JLabel("邮政编码",JLabel.CENTER));
     forAddNorth.add(postNum);
     forAddNorth.add(new JLabel("家庭住址",JLabel.CENTER));
     forAddNorth.add(homeAddress);
     forAddNorth.add(new JLabel("电话号码",JLabel.CENTER)); 
     forAddNorth.add(telNum);
     forAddNorth.add(new JLabel("创建密码:",JLabel.CENTER));
     forAddNorth.add(newPasswordField);
     forAddNorth.add(new JLabel("确认密码:",JLabel.CENTER));
     forAddNorth.add(confirmNewPasswordField);
     forAddNorth.setLayout(new GridLayout(4,6));
     //fam.setVisible(true);
     
    forAddSouth.setLayout(new FlowLayout(FlowLayout.RIGHT,6,6));
    forAddSouth.add(confirm);
    forAddSouth.add(concel);
     
     
    forAddCenter.setLayout(new BorderLayout(5,6)); 
    super.add(jpl,BorderLayout.WEST);
    forAddCenter.add(forAddNorth,BorderLayout.NORTH);    
    forAddCenter.add(new JScrollPane(table)); 
    forAddCenter.add(forAddSouth,BorderLayout.SOUTH);
    super.add(forAddCenter);   
      name.addTextListener(this);
      id.addTextListener(this);
      postNum.addTextListener(this);
      domNum.addTextListener(this);
      homeAddress.addTextListener(this);
      telNum.addTextListener(this);
     choice.addItemListener(this);
     domBuilding.addItemListener(this);
     jrb_male.addItemListener(this);
     jrb_female.addItemListener(this);
      

     jFind.addActionListener(this);
     jRefresh.addActionListener(this);
     confirm.addActionListener(this);
     
     sfd.pfsi.handin.addActionListener(this);
     sfd.pfsn.handin.addActionListener(this); 
     sfd.pfss.handin.addActionListener(this); 
     sfd.pfsa.handin.addActionListener(this);
   }
   
    
   public void reFresh(){
   	table.setVisible(false);
   	content.removeAllElements();
   	jishu=psql.SearchStudentDetail(content);
   	showNum.setText("人数为:"+jishu);
    table.setVisible(true);
   }
   
   
  public void setIdAndName(String setId,String setName){
  	id.setText(setId);
  	name.setText(setName);
  }   
   
   public void actionPerformed(ActionEvent e){
  	
   if(e.getSource()==confirm){
   		
       if(name.getText().equals("")||id.getText().equals(""))
    	{
    	JOptionPane.showMessageDialog(null, "帐号或姓名不能为空!");
    	return;
    	}
    	
    	String newPass=new String(newPasswordField.getPassword());
    	String conPass=new String(confirmNewPasswordField.getPassword());
    	if(!newPass.equals(conPass)){
    			JOptionPane.showMessageDialog(null, "密码不一致!");
    			return;
    	}
    	else {
    		StudentDetail[9]=newPass;
    		psql.insertStudentDetail(StudentDetail);
    		newPasswordField.setText("");
    	    confirmNewPasswordField.setText("");
    		reFresh();
    	}
    	
    	
   	}
   	
   	else if(e.getSource()==jFind){
   		sfd.setDisplay(true);
   	}
   	
   	
   	
   	else if(e.getSource()==jRefresh){  
   		this.reFresh(); 		
   	}
   	
   	else if(e.getSource()==sfd.pfsi.handin){
   		table.setVisible(false);
   		content.removeAllElements();
   		jishu = psql.SearchStudentDetailById(content,sfd.pfsi.jf_id.getText());
   		table.setVisible(true);
   	}
   	
   	else if(e.getSource()==sfd.pfsn.handin){
   		table.setVisible(false);
   		content.removeAllElements();
   		jishu = psql.SearchStudentDetailByName(content,sfd.pfsn.jf_id.getText());
   		table.setVisible(true);
   	}
   	
   	else if(e.getSource()==sfd.pfss.handin){
   		table.setVisible(false);
   		content.removeAllElements();
   		jishu = psql.SearchStudentDetailBySex(content,sfd.pfss.getSex());
   		table.setVisible(true);
   	}
   	
   	else if(e.getSource()==sfd.pfsa.handin){
   		table.setVisible(false);
   		content.removeAllElements();
   		jishu = psql.SearchStudentDetailByAge(content,Integer.parseInt(sfd.pfsa.age.getSelectedItem()));
   		table.setVisible(true);
   	}
  
      
     
     
   	
   	}
   	
 public void textValueChanged(TextEvent e){
    	if(e.getSource()==id)
    	{
    	StudentDetail[0] = id.getText();
    	}
    	
    	else if(e.getSource()==name){
    	StudentDetail[1] = name.getText();
    	}
    	
        else if(e.getSource()==homeAddress){
        StudentDetail[8] = homeAddress.getText();
        }
      
        else if(e.getSource()==telNum){
        StudentDetail[7] = telNum.getText();
        }   
        
        else if(e.getSource()==postNum){
        StudentDetail[6] = postNum.getText();
        }   
        
        else if(e.getSource()==domNum){
        StudentDetail[5] = domNum.getText();
        }   	
    }
	 
	 public void itemStateChanged(ItemEvent e){
	 	
   	 	if(e.getItemSelectable()==jrb_male){
   	 	StudentDetail[2] = "男";
   	 	}
   	 	
   	 	else if(e.getItemSelectable()==jrb_female){
   	 	StudentDetail[2] = "女";
   	 	}
   	 	
   	 	else if(e.getItemSelectable()==choice){
   	 		StudentDetail[3] = choice.getSelectedItem();  	 	
   	 	}
   	 	
   	 	
   	 	else if(e.getItemSelectable()==domBuilding){   	 	
   	 	StudentDetail[4] = domBuilding.getSelectedItem();
   	 	
   	 	
   	 }
   	}
	  	
}

⌨️ 快捷键说明

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