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

📄 sumpeople.java~11~

📁 这是一个用JAVA编写的学生管理系统
💻 JAVA~11~
字号:
package studentms;import com.borland.jbcl.layout.*;import java.awt.*;import java.sql.*;import javax.swing.*;import javax.swing.table.*;import java.util.*;import java.awt.event.*;import java.math.*;public class sumPeople extends JFrame {  XYLayout xYLayout1 = new XYLayout();  JLabel jLabel1 = new JLabel();  JComboBox jCType = new JComboBox();  JButton jBOK = new JButton();  JButton jBExit = new JButton();  JLabel jLabel2 = new JLabel();  JLabel jLabel3 = new JLabel();  JLabel jLabel4 = new JLabel();  JTextField jTMin = new JTextField();  JTextField jTMax = new JTextField();  JComboBox jCSex = new JComboBox();  JTextField jTClass = new JTextField();  Database DB=new Database();  ResultSet rs ;  String sql=new String();  public sumPeople() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  private void jbInit() throws Exception {    jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));    jLabel1.setText("选择统计选项:");    xYLayout1.setWidth(310);    xYLayout1.setHeight(146);    this.getContentPane().setLayout(xYLayout1);    jBOK.setFont(new java.awt.Font("Dialog", 0, 12));    jBOK.setText("确  定");    jBOK.addActionListener(new sumPeople_jBOK_actionAdapter(this));    jBExit.setFont(new java.awt.Font("Dialog", 0, 12));    jBExit.setText("取  消");    jBExit.addActionListener(new sumPeople_jBExit_actionAdapter(this));    jCType.addItem("学号");    jCType.addItem("性别");    jCType.addItem("班级");    jCType.addItem("出生年月");    jCType.setFont(new java.awt.Font("Dialog", 0, 12));    jCType.setSelectedIndex(-1);    jCType.addActionListener(new sumPeople_jCType_actionAdapter(this));    jCSex.addItem("男");    jCSex.addItem("女");    jCSex.setFont(new java.awt.Font("Dialog", 0, 12));    jCSex.setSelectedIndex(-1);    jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));    jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));    jLabel3.setText("从");    jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));    jLabel4.setText("至");    jTMax.setText("");    jTMin.setText("");    jTClass.setFont(new java.awt.Font("Dialog", 0, 12));    jTClass.setText("");    this.setTitle("人员统计");    this.getContentPane().add(jCType,     new XYConstraints(28, 57, 92, 23));    this.getContentPane().add(jLabel1,  new XYConstraints(29, 26, 94, 21));    this.getContentPane().add(jBOK,   new XYConstraints(63, 103, 74, 26));    this.getContentPane().add(jBExit,   new XYConstraints(167, 104, 74, 26));    this.getContentPane().add(jLabel2,      new XYConstraints(140, 26, 99, -1));    this.getContentPane().add(jTMin, new XYConstraints(155, 57, 40, 23));    this.getContentPane().add(jLabel3, new XYConstraints(138, 60, 14, 20));    this.getContentPane().add(jLabel4, new XYConstraints(203, 59, 15, 19));    this.getContentPane().add(jTMax, new XYConstraints(225, 57, 40, 23));    this.getContentPane().add(jCSex, new XYConstraints(142, 57, 58, 23));    this.getContentPane().add(jTClass,  new XYConstraints(142, 57, 58, 23));    jLabel2.setVisible(false);    jLabel3.setVisible(false);    jLabel4.setVisible(false);    jTMin.setVisible(false);    jTMax.setVisible(false);    jCSex.setVisible(false);    jTClass.setVisible(false);  } //根据不同的统计类型,显示不同的选项  void jCType_actionPerformed(ActionEvent e) {     if( jCType.getSelectedItem().equals("学号") ){       jLabel2.setText("请输入统计范围:");       jLabel2.setVisible(true);       jLabel3.setVisible(true);       jLabel4.setVisible(true);       jTMin.setVisible(true);       jTMax.setVisible(true);       jCSex.setVisible(false);       jTClass.setVisible(false);     }     else if(jCType.getSelectedItem().equals("性别")){       jLabel2.setText("请选择性别:");       jLabel2.setVisible(true);       jLabel3.setVisible(false);       jLabel4.setVisible(false);       jTMin.setVisible(false);       jTMax.setVisible(false);       jCSex.setVisible(true);       jTClass.setVisible(false);     }     else if(jCType.getSelectedItem().equals("班级")){       jLabel2.setText("请输入班级:");       jLabel2.setVisible(true);       jLabel3.setVisible(false);       jLabel4.setVisible(false);       jTMin.setVisible(false);       jTMax.setVisible(false);       jCSex.setVisible(false);       jTClass.setVisible(true);     }     else if(jCType.getSelectedItem().equals("出生年月")){       jLabel2.setText("请输入统计范围:");       jLabel2.setVisible(true);       jLabel3.setVisible(true);       jLabel4.setVisible(true);       jTMin.setVisible(true);       jTMax.setVisible(true);       jCSex.setVisible(false);       jTClass.setVisible(false);     }  }  //退出  void jBExit_actionPerformed(ActionEvent e) {       this.dispose() ;  } //显示统计结果  void listShow(){    stuShow stuList=new stuShow();    Dimension dlgSize = stuList.getPreferredSize();    Dimension frmSize = getSize();    Point loc = getLocation();    stuList.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);    stuList.pack();    stuList.show() ;    stuList.resultShow(rs);  }  //查询  void jBOK_actionPerformed(ActionEvent e) {    sql="select * from stuTable ";          //根据选项判断查询的类型          if (jCType.getSelectedIndex() ==0){              sql=sql+"  where  Num>='"+jTMin.getText().toString() +"'";              sql=sql+"and Num<='"+jTMax.getText().toString() +"'";          }          else if(jCType.getSelectedIndex() ==1){              sql=sql+"  where  Sex='"+jCSex.getSelectedItem().toString() +"'";          }          else if(jCType.getSelectedIndex() ==2){              sql=sql+"where Class='"+jTClass.getText().toString() +"'";          }          else if(jCType.getSelectedIndex() ==3){            sql=sql+"  where  Birthday>'"+jTMin.getText().toString() +"'";            sql=sql+"and Birthday<'"+jTMax.getText() .toString() +"'";          }          rs =DB.getResult(sql);          try{               if(rs.first()){            //判断记录是否存在                      listShow();                      this.dispose() ;                }                else{                     JOptionPane.showMessageDialog(null, "无满足条件的记录!");                }            }            catch (SQLException ex) {                 JOptionPane.showMessageDialog(null," failed!");            }  }}//************  以下为监听类  *************class sumPeople_jCType_actionAdapter implements java.awt.event.ActionListener {  sumPeople adaptee;  sumPeople_jCType_actionAdapter(sumPeople adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jCType_actionPerformed(e);  }}class sumPeople_jBExit_actionAdapter implements java.awt.event.ActionListener {  sumPeople adaptee;  sumPeople_jBExit_actionAdapter(sumPeople adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jBExit_actionPerformed(e);  }}class sumPeople_jBOK_actionAdapter implements java.awt.event.ActionListener {  sumPeople adaptee;  sumPeople_jBOK_actionAdapter(sumPeople adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jBOK_actionPerformed(e);  }}

⌨️ 快捷键说明

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