// 定义按钮,下拉框动作处理器
class ListenAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
Admin.setuId(tfArray[0].getText()); Admin.setuName(tfArray[1].getText());
Admin.setuPasswd(new String(pfArray[0].getPassword())); Admin.setuPosition(cbPosition.getSelectedItem().toString()); if (e.getSource() == bArray[0]) {// 点击注册按钮
if (tfArray[0].getText().equals(\) }
String[] strKey = new String[] { Admin.getuId(), }
if (!new String(pfArray[0].getPassword()).equals(new String( }
Admin.add(Admin);
if (cbPosition.getSelectedItem().equals(\仓库管理员\)) {
pfArray[1].getPassword()))) {
JOptionPane.showMessageDialog(null, \密码不一致!\); bArray[1].doClick(); return;
Admin.getuPosition() };
if (Admin.getKey().contains(strKey)) {
JOptionPane.showMessageDialog(null, \用户已存在!\); bArray[1].doClick(); return;
|| new String(pfArray[0].getPassword()).toString()
.equals(\)) {
}
// 添加监听器
bArray[0].addActionListener(new ListenAction()); bArray[1].addActionListener(new ListenAction()); bArray[2].addActionListener(new ListenAction()); cbPosition.addActionListener(new ListenAction()); lArray[6].addMouseListener(new ListenMouse());
add(pArray[3], BorderLayout.NORTH); add(jsp, BorderLayout.CENTER); add(pArray[2], BorderLayout.SOUTH);
JOptionPane.showMessageDialog(null, \用户名或密码不可为空bArray[1].doClick(); return;
\);
{
sma.setuId(tfArray[0].getText());
sma.setsId(cbSL.getSelectedItem().toString()); Admin.add(sma);
} else if (cbPosition.getSelectedItem().equals(\实验室管理员\)) }
bArray[1].doClick(); tfArray[0].setText(null); tfArray[1].setText(null); pfArray[0].setText(null); pfArray[1].setText(null); int selectedIndex = -1;
for (int i = 0; i < t.getRowCount(); i++) { }
if (selectedIndex == -1) { }
if (cbPosition.getSelectedItem().equals(\仓库管理员\)) {
lArray[5].setText(\仓库编号\); lArray[5].setVisible(true); cbSL.setVisible(true); cbSL.removeAllItems();
String[] sId = Admin.getsIdAll();
JOptionPane.showMessageDialog(null, \请先选择某一项!\); return;
int option = JOptionPane.showConfirmDialog(null, \是否确定 }
\提示\, JOptionPane.YES_NO_CANCEL_OPTION);
if (t.isRowSelected(i) == true)
selectedIndex = i;
lm.setuId(tfArray[0].getText());
lm.setlId(cbSL.getSelectedItem().toString()); Admin.add(lm);
} else if (e.getSource() == bArray[1]) {// 点击重置按钮
} else if (e.getSource() == bArray[2]) {// 点击删除按钮
} else {
删除?\,
if (option == JOptionPane.YES_OPTION) {
Admin.setuId((String) t.getValueAt(selectedIndex, Admin.setuPosition((String)
2));
0));
t.getValueAt(selectedIndex,
Admin.delete(Admin);
} else if (e.getSource() == cbPosition) {// 改变身份下拉框时
{ }
}
}
}
for (int i = 0; i < sId.length; i++)
cbSL.addItem(sId[i]); } else if (cbPosition.getSelectedItem().equals(\实验室管理员\)) }
lArray[5].setText(\实验室编号\); lArray[5].setVisible(true); cbSL.setVisible(true); cbSL.removeAllItems();
String[] sId = Admin.getlIdAll(); for (int i = 0; i < sId.length; i++)
cbSL.addItem(sId[i]); } else {
lArray[5].setVisible(false); cbSL.setVisible(false);
// 刷新数据表 remove(jsp);
String[] head = new String[] { \用户名\, \姓名\, \身份\ }; Object[][] data = Admin.getAll(); t = new JTable(data, head); t.setRowHeight(25); t.validate();
jsp = new JScrollPane(t); add(jsp, BorderLayout.CENTER); validate();
// 定义鼠标事件处理器
class ListenMouse extends MouseAdapter { }
public void mouseEntered(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
new ParameterSet();
lArray[6].setCursor(new Cursor(Cursor.HAND_CURSOR));
6、设备统计查询:
package com.niit.gui_event;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.*;
import com.niit.data.InData; import com.niit.data.OutData; import com.niit.logical.LabManager; import com.niit.logical.StoreManager;
public class Search extends JPanel {
/** * */
private static final long serialVersionUID = 1L;
private JRadioButton rbStore, rbLab, rbeId, rbSingleeId; private JComboBox cbStore, cbLab, cbeId; private JLabel lStore, lLab, leId; private JTable t; private JScrollPane jsp; private JPanel pUp, pDown, p;
private StoreManager sma; private InData inInfo; public Search() {
super(new BorderLayout());
rbStore = new JRadioButton(\仓库库存统计\, true); rbLab = new JRadioButton(\实验室库存统计\); rbeId = new JRadioButton(\所有设备\, true); rbSingleeId = new JRadioButton(\单个设备\); sma = new StoreManager(); inInfo = new InData();
cbStore = new JComboBox(sma.getsIdAll()); cbLab = new JComboBox(sma.getlIdAll()); cbeId = new JComboBox(sma.geteId()); lStore = new JLabel(\仓库编号\); lLab = new JLabel(\实验室编号\); leId = new JLabel(\设备编号\); cbLab.setVisible(false); lLab.setVisible(false); leId.setVisible(false); cbeId.setVisible(false); pUp = new JPanel(); pDown = new JPanel(); p = new JPanel(); pUp.add(rbStore); pUp.add(lStore); pUp.add(cbStore); pUp.add(rbLab); pUp.add(lLab); pUp.add(cbLab); pDown.add(rbeId); pDown.add(rbSingleeId); pDown.add(leId); pDown.add(cbeId);
p.setLayout(new GridLayout(2, 1)); p.add(pUp); p.add(pDown);