?? userlogin.java~6~
字號(hào):
package bookmanager;import java.awt.*;import javax.swing.*;import com.borland.jbcl.layout.*;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 userLogin extends JDialog { //定義結(jié)果集 ResultSet rs; //定義數(shù)據(jù)庫操作對(duì)象 private DBManager db =new DBManager(); //定義主窗口類,用于操作父窗體 BookManagerMain myMain; JPanel panel1 = new JPanel(); XYLayout xYLayout1 = new XYLayout(); XYLayout xYLayout2 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JTextField jTextFieldusername = new JTextField(); JButton jButtonOK = new JButton(); JButton jButtonCancel = new JButton(); JPasswordField jPasswordold = new JPasswordField(); //缺省構(gòu)造方法 public userLogin(Frame frame, String title, boolean modal) { super(frame, title, modal); try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } //缺省構(gòu)造方法 public userLogin() { this(null, "", false); } //定義可傳遞父類的構(gòu)造方法 public userLogin(BookManagerMain bMain) { this(null, "", false); myMain=bMain ; } //初始化對(duì)象 private void jbInit() throws Exception { panel1.setLayout(xYLayout2); this.getContentPane().setLayout(xYLayout1); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("用戶名"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("密碼"); jTextFieldusername.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldusername.setText(""); jButtonOK.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonOK.setText("確定"); jButtonOK.addMouseListener(new userLogin_jButtonOK_mouseAdapter(this)); jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonCancel.setText("取消"); jButtonCancel.addMouseListener(new userLogin_jButtonCancel_mouseAdapter(this)); jPasswordold.setText(""); xYLayout1.setWidth(400); xYLayout1.setHeight(271); panel1.add(jTextFieldusername, new XYConstraints(210, 49, 111, 38)); panel1.add(jPasswordold, new XYConstraints(211, 112, 111, 35)); panel1.add(jLabel1, new XYConstraints(59, 50, 99, 34)); panel1.add(jLabel2, new XYConstraints(60, 116, 80, 34)); panel1.add(jButtonCancel, new XYConstraints(212, 209, 94, 30)); panel1.add(jButtonOK, new XYConstraints(94, 208, 91, 31)); this.getContentPane().add(panel1, new XYConstraints(-2, 0, 400, 272)); } void jButtonCancel_mouseClicked(MouseEvent e) { this.dispose(); } void jButtonOK_mouseClicked(MouseEvent e) { //校驗(yàn)用戶名是否為空 if(jTextFieldusername.getText().trim() =="") { JOptionPane.showMessageDialog(null,"用戶名不可為空!"); return;} //校驗(yàn)密碼是否為空 if(jPasswordold.getText().trim() =="") {JOptionPane.showMessageDialog(null,"密碼不可為空!"); return;} String strSQL ; //生成sql操作語句,查詢要登陸的用戶名是否已經(jīng)存在,若存在執(zhí)行下一步操作,若不存在提示并返回 strSQL="select * from user where username='"+jTextFieldusername.getText().trim() +"' and password='"+jPasswordold.getText().trim()+"'"; rs=db.getResult(strSQL) ; if(rs != null)) {JOptionPane.showMessageDialog(null,"用戶名不存在,或密碼不正確!"); myMain.setEnable(false); } else { rs.first(); myMain.setEnable(true); } }}class userLogin_jButtonCancel_mouseAdapter extends java.awt.event.MouseAdapter { userLogin adaptee; userLogin_jButtonCancel_mouseAdapter(userLogin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonCancel_mouseClicked(e); }}class userLogin_jButtonOK_mouseAdapter extends java.awt.event.MouseAdapter { userLogin adaptee; userLogin_jButtonOK_mouseAdapter(userLogin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonOK_mouseClicked(e); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -