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

📄 loginframe.java~8~

📁 基于JB的网络数据库系统开发
💻 JAVA~8~
字号:
package simpleusers;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class LoginFrame extends JFrame {  Connection con = null;  Statement stmt = null;  ResultSet rs = null;  JLabel jLabel1 = new JLabel();  JLabel jLabel2 = new JLabel();  JTextField jT1 = new JTextField();  JPasswordField jP1 = new JPasswordField();  JButton jButton1 = new JButton();  JButton jButton2 = new JButton();  public LoginFrame() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  private void jbInit() throws Exception {    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));    jLabel1.setText("用户名");    jLabel1.setBounds(new Rectangle(63, 46, 61, 30));    this.setTitle("用户管理系统-用户登录");    this.getContentPane().setLayout(null);    jLabel2.setBounds(new Rectangle(63, 102, 61, 30));    jLabel2.setText("密     码");    jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));    jT1.setFont(new java.awt.Font("Dialog", 0, 16));    jT1.setText("");    jT1.setBounds(new Rectangle(137, 46, 131, 37));    jP1.setText("");    jP1.setBounds(new Rectangle(137, 102, 131, 37));    jButton1.setBounds(new Rectangle(69, 175, 69, 39));    jButton1.setFont(new java.awt.Font("Dialog", 0, 14));    jButton1.setText("确定");    jButton1.addActionListener(new LoginFrame_jButton1_actionAdapter(this));    jButton2.setText("重置");    jButton2.setFont(new java.awt.Font("Dialog", 0, 14));    jButton2.setBounds(new Rectangle(184, 175, 69, 39));    this.getContentPane().add(jLabel1, null);    this.getContentPane().add(jT1, null);    this.getContentPane().add(jP1, null);    this.getContentPane().add(jLabel2, null);    this.getContentPane().add(jButton1, null);    this.getContentPane().add(jButton2, null);  }  void jButton1_actionPerformed(ActionEvent e) {    String username=jT1.getText().trim();    String password=jP1.getText().trim();    String sql="select * from userandpwd where username='"+username+        "' and pwd='"+password+"'";    String msg=null;    try{      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");    }catch(ClassNotFoundException e1){      System.out.println("加载JDBC数据库驱动程序出错");    }    String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Test";    try{      con = DriverManager.getConnection(url, "sa", "");      stmt = con.createStatement();      rs = stmt.executeQuery(sql);    }catch(SQLException e2){      System.out.println("数据库连接出错");    }    try{      if (rs.next())         msg="欢迎你登录用户管理系统!\n"+             "你输入的用户名称为"+rs.getString("username")+             ".\n你输入的密码为"+rs.getString("pwd")+".";      else        msg="对不起,你输入的信息不正确!";    }catch(SQLException e3 ){      System.out.println("读取数据出错");    }    try{      rs.close();      stmt.close();      con.close();    }catch(SQLException e4){      System.out.println("关闭对象连接出错");    }    MessageFrame m1=new MessageFrame(msg);    m1.setSize(340,280);    this.dispose();    m1.show();  }}class LoginFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {  LoginFrame adaptee;  LoginFrame_jButton1_actionAdapter(LoginFrame adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton1_actionPerformed(e);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -