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

📄 1.学生登录界面.txt

📁 本系统是基于JBuilder和SQL2000开发的
💻 TXT
字号:
package library;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
import java.lang.String;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import java.awt.Font;
import java.sql.*;
import javax.swing.*;

public class Frame1 extends JFrame {
    JPanel contentPane;
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JPasswordField jPasswordField1 = new JPasswordField();
    JButton jButton1 = new JButton();
    Connection conn;
    JOptionPane jOptionPane1 = new JOptionPane();
    JLabel jLabel3 = new JLabel();
    public Frame1()
    {
        try
        {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
    }

    public void jbInit() throws Exception
    {
        try                                                 //try 和 catch 用于链接数据库
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//安装驱动
            String connURL ="jdbc:odbc:library";    //library为数据库名称
            String user = "sa";
            String pw = "123";
            conn=DriverManager.getConnection(connURL,user,pw);//前面已经定义coon
        }
        catch(Exception e)
        {
            System.out.println("class no found can not connect to sql server"+e);
        }                                            //数据库链接完毕

        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                closeWindow(e);
            }
        });

        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(xYLayout1);
        setSize(new Dimension(300, 200));
        setTitle("读者登陆界面");
        jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel1.setText("ID");
        jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel2.setText("密码");
        jButton1.setText("登陆");
        jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
        jTextField1.addActionListener(new Frame1_jTextField1_actionAdapter(this));
        jTextField1.setToolTipText("");
        jTextField1.setText("200511621223");
        jLabel3.setText("设计小组:谢嘉任   张淅茗");
        jPasswordField1.setText("200511621223");
        contentPane.add(jLabel1, new XYConstraints(41, 29, -1, -1));
        contentPane.add(jLabel2, new XYConstraints(32, 81, -1, -1));
        contentPane.add(jOptionPane1, new XYConstraints(372, 196, -1, -1));
        contentPane.add(jLabel3, new XYConstraints(33, 144, -1, -1));
        contentPane.add(jPasswordField1, new XYConstraints(102, 83, 137, -1));
        contentPane.add(jTextField1, new XYConstraints(102, 30, 137, 25));
        contentPane.add(jButton1, new XYConstraints(130, 113, 68, -1));
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    }

    public void jButton1_actionPerformed(ActionEvent e)
    {
        F1();
    }
       void F1(){
           try
           {
               String str1,str2;
               str1=jTextField1.getText();
               str2=new String(jPasswordField1.getPassword());
               Statement pstmt1 = conn.createStatement(ResultSet.
                                                  TYPE_SCROLL_SENSITIVE,
                                                  ResultSet.CONCUR_UPDATABLE);
               String sql= "select * from reader where ID='"+str1+"' AND 密码 = '"+str2+"' ";
               ResultSet rs2 = pstmt1.executeQuery(sql);
              if (!rs2.next())
                   {
                   JOptionPane.showMessageDialog(this,"帐号或者密码错误","错误",JOptionPane.ERROR_MESSAGE);
                   }
                   else
                   {
                     Frame2 f=new Frame2();
                     f.setVisible(true);
                     pstmt1.close();
                   }
                   dispose();
           }
           catch(Exception e)
           {
               System.err.println(e);
           }
       }   //F1()

       void closeWindow(WindowEvent e)
         {
             int intok = JOptionPane.showConfirmDialog(this,"确定要退出系统吗?","提示",JOptionPane.OK_OPTION);
             if(intok == 0)
             {
                 try
                 {
                 }
                 catch(Exception e1)
                 {
                     System.out.println("can't to close"+e1);
                 }
                 System.exit(0);
             }
             else
                 {return;}
       }

    public void jTextField1_actionPerformed(ActionEvent e)
    {
    }
}
class Frame1_jTextField1_actionAdapter implements ActionListener
{
    private Frame1 adaptee;
    Frame1_jTextField1_actionAdapter(Frame1 adaptee)
    {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e)
    {
        adaptee.jTextField1_actionPerformed(e);
    }
}

class Frame1_jButton1_actionAdapter implements ActionListener
{
    private Frame1 adaptee;
    Frame1_jButton1_actionAdapter(Frame1 adaptee)
    {
        this.adaptee = adaptee;
    }
    public void actionPerformed(ActionEvent e)
    {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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