⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useradd.java

📁 用java写的一个图书馆管理系统,应该说功能相当全面.包含所有源代码,从数据库的建立到客户端.
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class UserAdd
    extends JFrame
    implements ActionListener {
  DataBaseManager db = new DataBaseManager();
  ResultSet rs;
  Container c;
  JPanel panel1, panel2;
  JLabel userLabel, passwordLabel, passwordConfirmLabel, loginPrivelegeLabel;
  JTextField userTextField;
  JPasswordField passwordTextField, passwordConfirmTextField;
  JComboBox loginPrivelegeComboBox;
  JButton addBtn, cancelBtn;
  public UserAdd() {
    super("添加用户");
    c = getContentPane();
    c.setLayout(new BorderLayout());
    userLabel = new JLabel("用户名", JLabel.CENTER);
    passwordLabel = new JLabel("密码", JLabel.CENTER);
    passwordConfirmLabel = new JLabel("确认密码", JLabel.CENTER);
    loginPrivelegeLabel = new JLabel("登录权限", JLabel.CENTER);
    userTextField = new JTextField(10);
    passwordTextField = new JPasswordField(10);
    passwordConfirmTextField = new JPasswordField(10);
    loginPrivelegeComboBox = new JComboBox();
    loginPrivelegeComboBox.addItem("系统管理员");
    loginPrivelegeComboBox.addItem("书籍管理员");
    loginPrivelegeComboBox.addItem("借阅管理员");
    addBtn = new JButton("添加");
    cancelBtn = new JButton("取消");
    addBtn.addActionListener(this);
    cancelBtn.addActionListener(this);
    panel1 = new JPanel();
    panel1.setLayout(new GridLayout(4, 2));
    panel1.add(userLabel);
    panel1.add(userTextField);
    panel1.add(passwordLabel);
    panel1.add(passwordTextField);
    panel1.add(passwordConfirmLabel);
    panel1.add(passwordConfirmTextField);
    panel1.add(loginPrivelegeLabel);
    panel1.add(loginPrivelegeComboBox);
    c.add(panel1, BorderLayout.CENTER);
    panel2 = new JPanel();
    panel2.add(addBtn);
    panel2.add(cancelBtn);
    c.add(panel2, BorderLayout.SOUTH);
    setSize(300, 300);

  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == cancelBtn) {
      db.closeConnection();
      this.dispose();
    }
    else if (e.getSource() == addBtn) {
      try {
        String strSQL = "select * from userTable where userName='" +
            userTextField.getText().trim() + "'";
        if (userTextField.getText().trim().equals("")) {
          JOptionPane.showMessageDialog(null, "用户名不能为空!");
        }
        else if (new String(passwordTextField.getPassword()).trim().equals("")) {
          JOptionPane.showMessageDialog(null, "密码不能为空!");
        }
        else if (!new String(passwordTextField.getPassword()).trim().equals(
            new String(passwordConfirmTextField.getPassword()).trim())) {
          JOptionPane.showMessageDialog(null, "两次输入的密码不一致!");
        }
        else {
          if (db.getResult(strSQL).first()) {
            JOptionPane.showMessageDialog(null, "此用户已经存在,请重新输入用户名!");
          }
          else {
            strSQL = "insert into userTable values('" +
                userTextField.getText().trim() + "','" +
                new String(passwordTextField.getPassword()).
                trim() + "','" + loginPrivelegeComboBox.getSelectedItem() +
                "')";
            if (db.updateSql(strSQL)>0) {
              this.dispose();
              JOptionPane.showMessageDialog(null, "添加用户成功!");

            }
            else {
              JOptionPane.showMessageDialog(null, "添加用户失败!");
            }
          }
        }
      }
      catch (SQLException sqle) {
        System.out.println(sqle.toString());
      }
      catch (Exception ex) {
        System.out.println(ex.toString());
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -