?? userlogin.java~1~
字號:
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 { ResultSet rs; //定義結果集 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(); //缺省構造方法 public userLogin(Frame frame, String title, boolean modal) { super(frame, title, modal); try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } //缺省構造方法 public userLogin() { this(null, "", false); } //定義可傳遞父類的構造方法 public userLogin(BookManagerMain bMain) { this(null, "", false); myMain=bMain ; } //初始化對象 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); getContentPane().add(panel1, new XYConstraints(0, 0, 400, 258)); 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)); } void jButtonCancel_mouseClicked(MouseEvent e) { this.dispose(); } void jButtonOK_mouseClicked(MouseEvent e) { if(jTextFieldusername.getText().trim() =="") { JOptionPane.showMessageDialog(null,"用戶名不可為空!"); return;} if(jPasswordold.getText().trim() =="") {JOptionPane.showMessageDialog(null,"密碼不可為空!"); return;} String strSQL ; strSQL="select * from user where username='"+jTextFieldusername.getText().trim() +"' and password='"+jPasswordold.getText().trim()+"'"; rs=db.getResult(strSQL) ; if(rs.equals(null )) {JOptionPane.showMessageDialog(null,"用戶名不存在,或密碼不正確!"); myMain.setEnable(false); } else { 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); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -