📄 findstudentaction.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 + -