📄 useradd.java~9~
字号:
package Manager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class userAdd extends JFrame { private DBManager db =new DBManager();//定义数据库操作对象 XYLayout xYLayout1 = new XYLayout(); JLabel jLabel2 = new JLabel(); JButton jButtonCancel = new JButton(); JLabel jLabel1 = new JLabel(); JTextField jTextFieldusername = new JTextField(); JButton jButtonOK = new JButton(); JPasswordField jPasswordold = new JPasswordField(); JLabel jLabel3 = new JLabel(); JPasswordField jPasswordnew = new JPasswordField(); JLabel jLabel4 = new JLabel(); JComboBox jComboBoxpower = new JComboBox(); public userAdd() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { userAdd userAdd = new userAdd(); } private void jbInit() throws Exception { jPasswordold.setText(""); jButtonOK.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonOK.setText("添加"); jButtonOK.addMouseListener(new userAdd_jButtonOK_mouseAdapter(this)); jTextFieldusername.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldusername.setText(""); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("用户名"); jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonCancel.addMouseListener(new userAdd_jButtonCancel_mouseAdapter(this)); jButtonCancel.setText("取消"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("密码"); xYLayout1.setWidth(480); xYLayout1.setHeight(366); this.getContentPane().setLayout(xYLayout1); jLabel3.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel3.setText("确认密码"); jPasswordnew.setFont(new java.awt.Font("Dialog", 0, 16)); jPasswordnew.setText(""); jLabel4.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setText("登陆权限"); //jComboBoxpower中加入权限的值 jComboBoxpower.addItem(" 操作员"); jComboBoxpower.addItem(" 管理员"); jComboBoxpower.setFont(new java.awt.Font("Dialog", 0, 16)); this.setTitle("添加用户"); this.getContentPane().add(jTextFieldusername, new XYConstraints(263, 32, 111, 38)); this.getContentPane().add(jLabel2, new XYConstraints(113, 99, 80, 34)); this.getContentPane().add(jLabel1, new XYConstraints(112, 33, 99, 34)); this.getContentPane().add(jPasswordold, new XYConstraints(264, 95, 111, 35)); this.getContentPane().add(jPasswordnew, new XYConstraints(261, 157, 117, 35)); this.getContentPane().add(jLabel3, new XYConstraints(108, 160, 110, 36)); this.getContentPane().add(jButtonCancel, new XYConstraints(252, 301, 94, 30)); this.getContentPane().add(jButtonOK, new XYConstraints(134, 300, 91, 31)); this.getContentPane().add(jLabel4, new XYConstraints(112, 221, 105, 34)); this.getContentPane().add(jComboBoxpower, new XYConstraints(260, 224, 125, 26)); } //退出此窗口 void jButtonCancel_mouseClicked(MouseEvent e) { this.dispose(); } //添加新用户 void jButtonOK_mouseClicked(MouseEvent e) { String strSQL ; //判断是否添加用户名 if(jTextFieldusername.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"用户名不可为空 ,请确认!"); return; } //校验用户两次输入的密码是否一致 if(!jPasswordold.getText().trim().equals(jPasswordnew.getText().trim() ) ) {JOptionPane.showMessageDialog(null,"两次输入的密码不一致,请确认!"); return; } //校验用户输入的权限是否为空 if( jComboBoxpower.getSelectedItem().toString().trim().equals("")) { JOptionPane.showMessageDialog(null,"权限不可为空,请确认!"); return; } //生成sql语句,用户名和密码从相应文本框取得 strSQL="insert into user(username,password,power) values('"+jTextFieldusername.getText().trim() +"','"; strSQL= strSQL+jPasswordold.getText().trim()+"','"+jComboBoxpower.getSelectedItem().toString().trim()+"')"; //由DBManager对象执行过程,若成功返回成功信息,若失败返回失败提示 if(db.executeSql(strSQL)) {JOptionPane.showMessageDialog(null,"成功添加!"); } else { JOptionPane.showMessageDialog(null," 添加失败,请重新操作!"); } }}class userAdd_jButtonCancel_mouseAdapter extends java.awt.event.MouseAdapter { userAdd adaptee; userAdd_jButtonCancel_mouseAdapter(userAdd adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonCancel_mouseClicked(e); }}class userAdd_jButtonOK_mouseAdapter extends java.awt.event.MouseAdapter { userAdd adaptee; userAdd_jButtonOK_mouseAdapter(userAdd adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonOK_mouseClicked(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -