⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userlogin.java~13~

📁 这是一个用JAVA编写的书籍借阅管理系统
💻 JAVA~13~
字号:
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);
    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) {
   //若用户直接按取消,则取消用户权限
      myMain.setEnable("else");
          this.dispose();
  }

  void jButtonOK_mouseClicked(MouseEvent e) {
	   //校验用户名是否为空
         if(jTextFieldusername.getText().trim().equals(""))
             { JOptionPane.showMessageDialog(null,"用户名不可为空!");
                  return;}
      //校验密码是否为空
         if(jPasswordold.getText().trim().equals(""))
             {JOptionPane.showMessageDialog(null,"密码不可为空!");
                 return;}
        String strSQL ;
      //生成sql操作语句,查询要登陆的用户名是否存在,若存在执行下一步操作,若不存在提示并返回
        strSQL="select * from user where username='"+jTextFieldusername.getText().trim() +"' and password='"+jPasswordold.getText().trim()+"'";
               rs=db.getResult(strSQL) ;
   boolean  isexist=false;
                try {
                         isexist = rs.first();
                         }
                catch (SQLException ex1) {
                         }
  //若用户名不存在,提示警告信息
    if(!isexist)
              {JOptionPane.showMessageDialog(null,"用户名不存在,或密码不正确!");
             myMain.setEnable("else");
          }
      //  若用户名存在,设置权限
        else
          {
              try {
                rs.first();
            	myMain.setEnable(rs.getString("power").trim() );
               this.dispose();
              }
              catch (SQLException ex) {
              }

 	}
  }
}

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 + -