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

📄 findstudentaction.java

📁 掌握 JDBC 驱动程序的加载方法和JDBC-ODBC桥URL的形式; 掌握使用JDBC连接数据库的步骤; 掌握使用JDBC发送SQL语句的基本步骤; 掌握使用JDBC处理SQL查询结果集
💻 JAVA
字号:
package cn.edu.csu.oo.gui.project.action.studentaction;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import cn.edu.csu.oo.gui.project.dao.studentdao.StudentDao;
import cn.edu.csu.oo.gui.project.dao.studentdao.impl.StudentDaoImpl;
import cn.edu.csu.oo.gui.project.view.panel.StudentFindPanel;
import cn.edu.csu.oo.gui.project.vo.StudentVo;

public class FindStudentAction implements ActionListener {
  private StudentFindPanel studentFindPane;
  public FindStudentAction(StudentFindPanel studentFindPane){
    this.studentFindPane = studentFindPane;
  }
  public void actionPerformed(ActionEvent e) {
    String name = e.getActionCommand();
    StudentDao dao = new StudentDaoImpl();
    if(name.equals("查找")){
      Vector v = null;

      if(studentFindPane.buildStuIdBox().isSelected()){
        int stuId = Integer.parseInt(studentFindPane.getStuIdTxt().getText());
        v = dao.getStudentInfoByStuId(stuId);
      }else if(studentFindPane.buildStuNameBox().isSelected()){
        String stuName = studentFindPane.getStuNameTxt().getText();
        v = dao.getStudentByName(stuName);
      }else if(studentFindPane.buildStuMajorBox().isSelected()){
        String stuMajor = studentFindPane.buildMajorComboBox().getSelectedItem().toString();
        v = dao.getStudentByMajor(stuMajor);
      }
      DefaultTableModel model = (DefaultTableModel)studentFindPane.buildJTable().getModel();
      int rows = model.getRowCount();
      for(int i = rows -1; i >= 0; i--){
        model.removeRow(i);
      }
      Iterator iter = v.iterator();
      while(iter.hasNext()){
        StudentVo value = (StudentVo)iter.next();
        Object[] data = {new Integer(value.getStudentNo()),value.getStudentName(),value.getStudentSex(),
            value.getStudentMajor(),new Integer(value.getStudentGrade()),value.getStudentMail(),
            value.getStudentAddress(),value.getStudentMobile(),value.getStudentDate().substring(0,10)};
        model.addRow(data);
      }
    }
  }

}

⌨️ 快捷键说明

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