📄 admin.java
字号:
});
updateInformationButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
ID = editTextField.getText();
if (ID!="") {
if (informationPasswordField[0].getText().equals(informationPasswordField[1].getText())) {
Thread runner = new Thread() {
public void run() {
member = new Members();
member.setType(false);
//for updting the members database
member.update("UPDATE Admin SET Password = '" + informationPasswordField[0].getText()
+ "', NAME = '"+informationTextField.getText()+"' WHERE ID=" +ID);
Log log =new Log("\n "+"UpdateAdmin:"+ID + "," + informationPasswordField[0].getText());
editTextField.setText(null);
informationTextField.setText(null);
informationPasswordField[0].setText(null);
informationPasswordField[1].setText(null);
JOptionPane.showMessageDialog(null, "数据操作成功!", "信息", JOptionPane.YES_OPTION);
}
};
runner.start();
}
//if the password is wrong
else
JOptionPane.showMessageDialog(null, "密码输入错误", "出错", JOptionPane.ERROR_MESSAGE);
}
//if there is a missing data, then display Message Dialog
else
JOptionPane.showMessageDialog(null, "请将信息填写完整", "警告", JOptionPane.WARNING_MESSAGE);
}
});
//for adding the action listener for the button to dispose the frame
OKButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
dispose();
}
});
}
private void addAdmin(JComponent cp){
cp.setLayout(new BorderLayout());
northPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
northLabel1.setFont(new Font("Default", Font.BOLD, 14));
northPanel1.add(northLabel1);
cp.add("North", northPanel1);
centerPanel1.setLayout(new BorderLayout());
centerPanel1.setBorder(BorderFactory.createTitledBorder("添加管理员:"));
informationLabelPanel1.setLayout(new GridLayout(3, 1, 1, 1));
informationTextFieldPanel1.setLayout(new GridLayout(3, 1, 1, 1));
informationLabelPanel1.add(new JLabel(" 管理员姓名: "));
for (int i = 0; i < informationLabel1.length; i++) {
informationLabelPanel1.add(informationLabel1[i] = new JLabel(informaionString[i]));
informationLabel1[i].setFont(new Font("Default", Font.BOLD, 13));
}
centerPanel1.add("West", informationLabelPanel1);
informationTextFieldPanel1.add(informationTextField1);
informationTextField1.setFont(new Font("Default", Font.PLAIN, 13));
for(int i=0;i<2;i++){
informationTextFieldPanel1.add(informationPasswordField1[i]=new JPasswordField(25) );
informationPasswordField[i].setFont(new Font("Default", Font.PLAIN, 13));
}
centerPanel1.add("East", informationTextFieldPanel1);
insertInformationButtonPanel1.setLayout(new FlowLayout(FlowLayout.RIGHT));
insertInformationButton1.setFont(new Font("Default", Font.BOLD, 13));
insertInformationButtonPanel1.add(insertInformationButton1);
centerPanel1.add("South", insertInformationButtonPanel1);
cp.add("Center", centerPanel1);
southPanel1.setLayout(new FlowLayout(FlowLayout.RIGHT));
OKButton1.setFont(new Font("Default", Font.BOLD, 13));
southPanel1.add(OKButton1);
southPanel1.setBorder(BorderFactory.createEtchedBorder());
cp.add("South", southPanel1);
insertInformationButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
name = informationTextField1.getText();
if (!name.equals("")&&!informationPasswordField1[0].getText().equals("")
&&!informationPasswordField1[1].getText().equals("")) {
if (informationPasswordField1[0].getText().equals(informationPasswordField1[1].getText())) {
Thread runner = new Thread() {
public void run() {
member = new Members();
member.setType(false);
member.update("INSERT INTO Admin (Name,Password) VALUES ('" +name+"','"
+informationPasswordField1[0].getText()+"')");
//for setting the array of JTextField & JPasswordField to null
informationTextField1.setText(null);
informationPasswordField1[0].setText(null);
informationPasswordField1[1].setText(null);
Log log =new Log("\n"+"AddAdmin:"+name+","+informationPasswordField1[0].getText());
JOptionPane.showMessageDialog(null, "数据操作成功!", "信息", JOptionPane.YES_OPTION);
}
};
runner.start();
}
//if the password is wrong
else
JOptionPane.showMessageDialog(null, "密码输入错误!", "出错", JOptionPane.ERROR_MESSAGE);
}
//if there is a missing data, then display Message Dialog
else
JOptionPane.showMessageDialog(null, "请将信息填写完整", "警告", JOptionPane.WARNING_MESSAGE);
}
});
//for adding the action listener for the button to dispose the frame
OKButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
dispose();
}
});
}
private void removeAdmin(JComponent cp){
cp.setLayout(new BorderLayout());
northPanel3.setLayout(new FlowLayout(FlowLayout.CENTER));
title.setFont(new Font("Default", Font.BOLD, 14));
northPanel3.add(title);
cp.add("North", northPanel);
centerPanel3.setLayout(new BorderLayout());
removePanel.setLayout(null);
removeLabel.setBounds(20, 30, 180, 30);
removeTextField.setBounds(190, 30, 150, 30);
removePanel.add(removeLabel);
removePanel.add(removeTextField);
centerPanel3.add("Center", removePanel);
removeMemberPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
removeMemberPanel.add(removeButton);
centerPanel3.add("South", removeMemberPanel);
centerPanel3.setBorder(BorderFactory.createTitledBorder("删除管理员:"));
cp.add("Center", centerPanel3);
removeLabel.setFont(new Font("Default", Font.BOLD, 13));
removeTextField.setFont(new Font("Default", Font.PLAIN, 13));
exitButton.setFont(new Font("Default", Font.BOLD, 13));
removeButton.setFont(new Font("Default", Font.BOLD, 13));
southPanel3.setLayout(new FlowLayout(FlowLayout.RIGHT));
southPanel3.add(exitButton);
southPanel3.setBorder(BorderFactory.createEtchedBorder());
cp.add("South", southPanel3);
removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
ID = removeTextField.getText();
if (!ID.equals("")) {
Thread runner = new Thread() {
public void run() {
member = new Members();
member.setType(false);
member.connection("SELECT * FROM Admin WHERE ID LIKE '" + ID+"'");
if (member.getName()!=null) {
member.update("DELETE FROM Admin WHERE ID LIKE '" + ID+"'");
Log log =new Log("\n"+"AddAdmin:"+name+","+member.getPassword());
//for setting the JTextField to null
removeTextField.setText(null);
JOptionPane.showMessageDialog(null, "数据操作成功!", "信息", JOptionPane.YES_OPTION);
}
else
JOptionPane.showMessageDialog(null,"该管理员不存在!","警告",JOptionPane.WARNING_MESSAGE);
}
};
runner.start();
}
//if there is a missing data, then display Message Dialog
else {
JOptionPane.showMessageDialog(null, "请填写管理员名", "警告", JOptionPane.WARNING_MESSAGE);
}
}
});
//for adding the action listener for the button to dispose the frame
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
dispose();
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -