?? useradd.java~3~
字號:
package bookmanager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.awt.event.*;import java.sql.*;/** * <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(); JButton jButtonCancel = new JButton(); JLabel jLabel2 = new JLabel(); JButton jButtonOK = new JButton(); JPasswordField jPasswordold = new JPasswordField(); JLabel jLabel1 = new JLabel(); JTextField jTextFieldusername = new JTextField(); public userAdd() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { userAdd userAdd = new userAdd(); } private void jbInit() throws Exception { jTextFieldusername.setText(""); jTextFieldusername.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("用戶名"); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jPasswordold.setText(""); jButtonOK.setText("添加"); jButtonOK.addMouseListener(new userAdd_jButtonOK_mouseAdapter(this)); jButtonOK.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("密碼"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonCancel.setText("取消"); jButtonCancel.addMouseListener(new userAdd_jButtonCancel_mouseAdapter(this)); jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16)); this.getContentPane().setLayout(xYLayout1); xYLayout1.setWidth(378); xYLayout1.setHeight(262); this.setTitle("添加用戶"); this.getContentPane().add(jTextFieldusername, new XYConstraints(207, 28, 111, 38)); this.getContentPane().add(jLabel2, new XYConstraints(57, 95, 80, 34)); this.getContentPane().add(jPasswordold, new XYConstraints(208, 91, 111, 35)); this.getContentPane().add(jLabel1, new XYConstraints(56, 29, 99, 34)); this.getContentPane().add(jButtonCancel, new XYConstraints(206, 177, 94, 30)); this.getContentPane().add(jButtonOK, new XYConstraints(88, 176, 91, 31)); } void jButtonCancel_mouseClicked(MouseEvent e) { this.dispose(); }//首先校驗輸入是否為空,然后檢驗用戶名是否已存在,然后執行插入操作 void jButtonOK_mouseClicked(MouseEvent e) { String strSQL ; //校驗用戶名是否為空 if(jTextFieldusername.GetText().Trim().eques("")) {JOptionPane.showMessageDialog(null,"用戶名不許為空!"); return;} //校驗密碼是否為空 if(jPasswordold.GetText().Trim().eques("")) {JOptionPane.showMessageDialog(null,"密碼不許為空!"); return;} //生成sql操作語句,查詢要添加的用戶名是否已經存在,若存在執行刪除,若不存在提示并返回 strSQL="select * from user where username='"+jTextFieldusername.getText().trim() +"'"; rs=db.getResult(strSQL) ; if(rs.First()) {JOptionPane.showMessageDialog(null,"用戶名已存在!"); } else { //然后執行插入操作 strSQL="insert into user(username,password) values('"+jTextFieldusername.getText().trim() +"','"+jPasswordold.getText().trim()+"')"; //由數據庫操作對象執行數據庫操作,并返回操作成功失敗的提示信息 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 + -