📄 toppanel.java
字号:
package com.zlf.qqserver.usermngpanel;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import com.zlf.dao.DaoFactory;
import com.zlf.dao.DeptDao;
import com.zlf.dao.UserDao;
import com.zlf.qqserver.ServerMain;
/**
* 上方面板,查询区
*
* @author zlf
*
*/
public class TopPanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel userNoLable = new JLabel("用户编号:");
private JTextField userNoText = new JTextField(12);
private JLabel userNameLable = new JLabel("姓名:");
private JTextField userNameText = new JTextField(12);
private JLabel deptNameLable = new JLabel("部门:");
private JComboBox deptNameCombo=null;
private JButton searchBtn = new JButton("查询");
private DeptDao dao = DaoFactory.newInstance().createDeptDao();
private HashMap h=new HashMap();
private UserDao userDao=DaoFactory.newInstance().createUserDao();
private HashMap hashMap=new HashMap();
private Vector data=null;
public TopPanel(final ServerMain f) {
iniDeptCombo();
//查询按钮的监听
searchBtn.addActionListener(new AbstractAction(){
/**
*
*/
private static final long serialVersionUID = 6752278908253303411L;
public void actionPerformed(ActionEvent e) {
//根据条件查找
//System.out.println(deptNameCombo.getSelectedItem());
if (userNoText.getText().equals("") && userNameText.getText().equals("")
&& deptNameCombo.getSelectedItem().equals("")){
//返回所有用户
hashMap.put("1", "");
data =userDao.selectUser(hashMap);
hashMap.clear();
}else if (!userNoText.getText().equals("")){
//根据编号返回数据
HashMap m=new HashMap();
m.put("1", userNoText.getText());
hashMap.put("11", m);
data =userDao.selectUser(hashMap);
hashMap.clear();
}else if (!userNameText.getText().equals("")){
//根据名称返回数据
HashMap m=new HashMap();
m.put("2", userNameText.getText());
hashMap.put("11", m);
data =userDao.selectUser(hashMap);
hashMap.clear();
}else if (!deptNameCombo.getSelectedItem().equals("")){
//根据部门信息返回数据
//将部门名称转为部门编号
h.put("6", deptNameCombo.getSelectedItem());
String deptId=(String) dao.selectDept(h).get(0);
h.clear();
HashMap m=new HashMap();
m.put("3", deptId);
hashMap.put("11", m);
data =userDao.selectUser(hashMap);
hashMap.clear();
}
// 刷新表格
f.getUserMngPanel().getCenterPanel().getDataModel().setData(
data);
if (data.size()==0){
JOptionPane.showMessageDialog(f, "没有查到相应的信息!", "提示框",
JOptionPane.WARNING_MESSAGE);
}
//清空查询条件
userNoText.setText("");
userNameText.setText("");
deptNameCombo.setSelectedItem("");
}
});
this.setBorder(new TitledBorder("查询条件"));
this.add(userNoLable);
this.add(userNoText);
this.add(Box.createHorizontalStrut(20));
this.add(userNameLable);
this.add(userNameText);
this.add(Box.createHorizontalStrut(20));
this.add(deptNameLable);
this.add(deptNameCombo);
this.add(Box.createHorizontalStrut(20));
this.add(searchBtn);
}
public void iniDeptCombo(){
// 从数据库中查找出部门的名称
h.put("3", "");
String[] stDeptName=(String[]) dao.selectDept(h).get(0);
h.clear();
//初始化下拉框
deptNameCombo = new JComboBox(stDeptName);
}
public JComboBox getDeptNameCombo() {
return deptNameCombo;
}
public void setDeptNameCombo(JComboBox deptNameCombo) {
this.deptNameCombo = deptNameCombo;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -