📄 userlogin.java~2~
字号:
package studentms;import java.awt.*;import javax.swing.*;import java.sql.*;import com.borland.jbcl.layout.*;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 userLogin extends JDialog { ResultSet rs; //定义结果集 private Database db =new Database();//定义数据库操作对象 menuClass myMain; //定义主窗口类,用于操作父窗体 JPanel panel1 = new JPanel(); BorderLayout borderLayout1 = new BorderLayout(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel2 = new JLabel(); JButton jBCancel = new JButton(); JLabel jLabel1 = new JLabel(); JTextField jTUserName = new JTextField(); JButton jBOK = new JButton(); JPasswordField jTPassword = 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(menuClass pmain) { this(null, "", false); myMain=pmain; } private void jbInit() throws Exception { panel1.setLayout(borderLayout1); this.getContentPane().setLayout(xYLayout1); jLabel2.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel2.setText("密码:"); jBCancel.setFont(new java.awt.Font("Dialog", 0, 14)); jBCancel.setText("取 消"); jBCancel.addMouseListener(new userLogin_jBCancel_mouseAdapter(this)); jLabel1.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel1.setText("用户名:"); jTUserName.setFont(new java.awt.Font("Dialog", 0, 14)); jTUserName.setText(""); jBOK.setFont(new java.awt.Font("Dialog", 0, 14)); jBOK.setText("确 定"); jBOK.addMouseListener(new userLogin_jBOK_mouseAdapter(this)); jTPassword.setFont(new java.awt.Font("Dialog", 0, 14)); jTPassword.setText(""); //jComboBoxpower.add(null,"管理员") ; // jComboBoxpower.add(null,"操作员") ; //jComboBoxpower.add("管理员",null) ; // jComboBoxpower.add("操作员",null) ; xYLayout1.setWidth(314); xYLayout1.setHeight(179); getContentPane().add(panel1, new XYConstraints(0, 0, -1, -1)); this.getContentPane().add(jTUserName, new XYConstraints(136, 38, 111, 25)); this.getContentPane().add(jLabel2, new XYConstraints(67, 80, 51, 22)); this.getContentPane().add(jLabel1, new XYConstraints(64, 38, 68, 24)); this.getContentPane().add(jTPassword, new XYConstraints(137, 77, 111, 25)); this.getContentPane().add(jBOK, new XYConstraints(66, 125, 75, 26)); this.getContentPane().add(jBCancel, new XYConstraints(172, 125, 75, 26)); } void jBCancel_mouseClicked(MouseEvent e) { this.dispose(); } void jBOK_mouseClicked(MouseEvent e) { if(jTUserName.getText().trim() =="") { JOptionPane.showMessageDialog(null,"用户名不可为空!"); return;} if(jTPassword.getText().trim() =="") {JOptionPane.showMessageDialog(null,"密码不可为空!"); return;} String strSQL ; strSQL="select * from user where username='"+jTUserName.getText().trim() +"' and password='"+jTPassword.getText().trim()+"'"; rs=db.getResult(strSQL) ; boolean isexist=false; try { isexist = rs.first(); } catch (SQLException ex1) { } if(!isexist ) {JOptionPane.showMessageDialog(null,"用户名不存在,或密码不正确!"); // myMain.setEnable(false,false); } else { try { rs.first(); if (rs.getString("power").equals("管理员")) { //myMain.setEnable(true,true); this.dispose(); } else { //myMain.setEnable(true,false); //this.dispose(); } } catch (SQLException ex) { } } }}class userLogin_jBCancel_mouseAdapter extends java.awt.event.MouseAdapter { userLogin adaptee; userLogin_jBCancel_mouseAdapter(userLogin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jBCancel_mouseClicked(e); }}class userLogin_jBOK_mouseAdapter extends java.awt.event.MouseAdapter { userLogin adaptee; userLogin_jBOK_mouseAdapter(userLogin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jBOK_mouseClicked(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -