?? useradd.java~3~
字號:
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(ID_User_sequence.nextval,'" +
UserTextField.getText().trim() + "','" +
PasswordTextField.getText().
trim() + "','" + LoginPrivelegeComboBox.getSelectedItem() +
"')";
if (db.updateSql(strSQL)) {
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 + -