📄 admin.java
字号:
package lib;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.sql.*;
public class Admin extends JInternalFrame {
private JTabbedPane tabbedPane;
private ImageIcon icon;
private JPanel northPanel = new JPanel();
private JLabel northLabel = new JLabel("管理员信息");
private JPanel centerPanel = new JPanel();
private JPanel editPanel = new JPanel();
private JPanel editInformationPanel = new JPanel();
private JPanel editInformationLabelPanel = new JPanel();
private JPanel editInformationTextFieldPanel = new JPanel();
private JPanel editButtonPanel = new JPanel();
private JLabel editLabel = new JLabel("管理员ID: ");
private JTextField editTextField = new JTextField(25);
private JButton editButton = new JButton("编辑",new ImageIcon(ClassLoader.getSystemResource("images/edit.gif")));
private JPanel informationPanel = new JPanel();
private JPanel informationLabelPanel = new JPanel();
private JLabel[] informationLabel = new JLabel[3];
private String[] informaionString = {" 输入密码: ", " 重新输入密码: ","管理员姓名:"};
private JPanel informationTextFieldPanel = new JPanel();
private JPasswordField[] informationPasswordField = new JPasswordField[2];
private JTextField informationTextField = new JTextField();
private JPanel updateInformationButtonPanel = new JPanel();
private JButton updateInformationButton = new JButton("更新信息",new ImageIcon(ClassLoader.getSystemResource("images/add.gif")));
private JPanel southPanel = new JPanel();
private JButton OKButton = new JButton("退出",new ImageIcon(ClassLoader.getSystemResource("images/exit.gif")));
private Members member;
private String ID,name;
private String URL = "jdbc:odbc:JLibrary";
private JPanel northPanel1 = new JPanel();
private JLabel northLabel1 = new JLabel("管理员信息");
private JPanel centerPanel1 = new JPanel();
private JPanel informationLabelPanel1 = new JPanel();
private JLabel[] informationLabel1 = new JLabel[2];
private JPanel informationTextFieldPanel1 = new JPanel();
private JTextField informationTextField1 = new JTextField(25);
private JPasswordField[] informationPasswordField1=new JPasswordField[2] ;
private JPanel insertInformationButtonPanel1 = new JPanel();
private JButton insertInformationButton1 = new JButton("插入管理员记录",new ImageIcon(ClassLoader.getSystemResource("images/add.gif")));
private JPanel southPanel1 = new JPanel();
private JButton OKButton1 = new JButton("退出",new ImageIcon(ClassLoader.getSystemResource("images/exit.gif")));
private JPanel northPanel3 = new JPanel();
private JLabel title = new JLabel("管理员信息");
private JPanel centerPanel3 = new JPanel();
private JPanel removePanel = new JPanel();
private JLabel removeLabel = new JLabel(" 填写管理员ID: ");
private JTextField removeTextField = new JTextField();
private JPanel removeMemberPanel = new JPanel();
private JButton removeButton = new JButton("删除",new ImageIcon(ClassLoader.getSystemResource("images/delete.gif")));
private JPanel southPanel3 = new JPanel();
private JButton exitButton = new JButton("退出",new ImageIcon(ClassLoader.getSystemResource("images/exit.gif")));
public Admin() {
super("编辑管理员信息", false, true, false, true);
Container cp = this.getContentPane();
tabbedPane = new JTabbedPane();
icon = createImageIcon("images/user.gif");
JComponent panel1 = new JPanel();
tabbedPane.addTab("编辑", icon, panel1,
"编辑管理员信息");
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
editAdmin(panel1);
JComponent panel2 = new JPanel();
tabbedPane.addTab("插入", icon, panel2,
"添加管理员");
tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
addAdmin(panel2);
JComponent panel3 = new JPanel();
tabbedPane.addTab("删除", icon, panel3,
"删除管理员信息");
tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
removeAdmin(panel3);
cp.add(tabbedPane);
setVisible(true);
pack();
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = ClassLoader.getSystemResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
private void editAdmin(JComponent cp){
cp.setLayout(new BorderLayout());
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
northLabel.setFont(new Font("Default", Font.BOLD, 14));
northPanel.add(northLabel);
cp.add("North", northPanel);
centerPanel.setLayout(new BorderLayout());
editPanel.setLayout(new BorderLayout());
editPanel.setBorder(BorderFactory.createTitledBorder(" 管理员ID: "));
editInformationPanel.setLayout(new BorderLayout());
editInformationLabelPanel.setLayout(new GridLayout(1, 1, 1, 1));
editInformationLabelPanel.add(editLabel);
editLabel.setFont(new Font("Default", Font.BOLD, 13));
editInformationPanel.add("West", editInformationLabelPanel);
editInformationTextFieldPanel.setLayout(new GridLayout(1, 1, 1, 1));
editInformationTextFieldPanel.add(editTextField);
editTextField.setFont(new Font("Default", Font.PLAIN, 13));
editInformationPanel.add("East", editInformationTextFieldPanel);
editPanel.add("North", editInformationPanel);
editButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
editButtonPanel.add(editButton);
editButton.setFont(new Font("Default", Font.BOLD, 13));
editPanel.add("Center", editButtonPanel);
centerPanel.add("North", editPanel);
informationPanel.setLayout(new BorderLayout());
informationPanel.setBorder(BorderFactory.createTitledBorder("修改信息: "));
informationLabelPanel.setLayout(new GridLayout(3, 1, 1, 1));
informationTextFieldPanel.setLayout(new GridLayout(3, 1, 1, 1));
informationLabelPanel.add(informationLabel[2] = new JLabel(informaionString[2]));
informationLabel[2].setFont(new Font("Default", Font.BOLD, 13));
for (int i = 0; i < 2; i++) {
informationLabelPanel.add(informationLabel[i] = new JLabel(informaionString[i]));
informationLabel[i].setFont(new Font("Default", Font.BOLD, 13));
}
informationPanel.add("West", informationLabelPanel);
informationTextFieldPanel.add(informationTextField = new JTextField());
informationTextField.setFont(new Font("Default", Font.PLAIN, 13));
for(int i=0;i<2;i++){
informationTextFieldPanel.add(informationPasswordField[i] = new JPasswordField(25));
informationPasswordField[i].setFont(new Font("Default", Font.PLAIN, 13));
}
informationPanel.add("East", informationTextFieldPanel);
updateInformationButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
updateInformationButton.setFont(new Font("Default", Font.BOLD, 13));
updateInformationButtonPanel.add(updateInformationButton);
informationPanel.add("South", updateInformationButtonPanel);
centerPanel.add("Center", informationPanel);
cp.add("Center", centerPanel);
southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
OKButton.setFont(new Font("Default", Font.BOLD, 13));
southPanel.add(OKButton);
southPanel.setBorder(BorderFactory.createEtchedBorder());
cp.add("South", southPanel);
editButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
ID = editTextField.getText();
if (ID!="") {
Thread runner = new Thread() {
public void run() {
member = new Members();
member.setType(false);
member.connection("SELECT * FROM Admin WHERE ID LIKE " + "'"+ID+"'");
if (member.getPassword()!=null) {
informationPasswordField[0].setText(member.getPassword());
informationPasswordField[1].setText(member.getPassword());
informationTextField.setText(member.getName());
}
else {
JOptionPane.showMessageDialog(null, "请输入正确的管理员ID号码!", "出错", JOptionPane.ERROR_MESSAGE);
editTextField.setText(null);
}
}
};
runner.start();
}
else {
JOptionPane.showMessageDialog(null, "请填写管理员ID号码", "警告", JOptionPane.WARNING_MESSAGE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -