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

📄 login.java

📁 这是一个教学管理代码
💻 JAVA
字号:
package sims;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class Login extends JFrame implements ActionListener
{
    JLabel 登陆 = new JLabel();
    JLabel 用户名 = new JLabel();
    JLabel 密码 = new JLabel();
    JTextField 用户名输入 = new JTextField();
    JPasswordField 密码输入 = new JPasswordField();
    JButton 确定 = new JButton();
    JButton 退出 = new JButton();

    public Login()
    {
        Container c=this.getContentPane();
        c.setLayout(null);
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


    private void jbInit() throws Exception
    {
        登陆.setBackground(Color.white);
        登陆.setFont(new java.awt.Font("楷体_GB2312", Font.BOLD, 26));
        登陆.setForeground(Color.blue);
        登陆.setText("系统登陆");
        登陆.setBounds(new Rectangle(144, 48, 125, 30));
        this.getContentPane().setBackground(new Color(200, 233, 100));
        确定.setBounds(new Rectangle(106, 214, 78, 34));
        确定.setFont(new java.awt.Font("华文仿宋", Font.BOLD, 18));
        确定.setForeground(Color.orange);
        确定.setText("确定");
        退出.setBounds(new Rectangle(207, 214, 81, 32));
        退出.setFont(new java.awt.Font("华文仿宋", Font.BOLD, 18));
        退出.setForeground(Color.orange);
        退出.setText("退出");
        this.getContentPane().add(登陆);
        密码输入.setBounds(new Rectangle(156, 160, 127, 29));
        用户名输入.setBounds(new Rectangle(155, 108, 128, 30));
        密码.setFont(new java.awt.Font("楷体_GB2312", Font.BOLD, 20));
        密码.setForeground(Color.magenta);
        密码.setText("密码");
        密码.setBounds(new Rectangle(78, 155, 97, 39));
        this.getContentPane().add(用户名);
        this.getContentPane().add(密码);
        this.getContentPane().add(用户名输入);
        this.getContentPane().add(密码输入);
        this.getContentPane().add(确定);
        this.getContentPane().add(退出);
        用户名.setFont(new java.awt.Font("楷体_GB2312", Font.BOLD, 20));
        用户名.setForeground(Color.magenta);
        用户名.setText("用户名");
        用户名.setBounds(new Rectangle(80, 108, 86, 29));
        确定.addActionListener(this);
        退出.addActionListener(this);

        setVisible(true);
        setSize(400,350);
        setTitle("系统登陆");
        show();


    }

    public void actionPerformed(ActionEvent e)
   {
       if(e.getSource()==确定)
       {/*
           try
           {
               Connection con = new connection().createConnection();
               String sql = "select * from login";
               Statement stmt = con.createStatement();
               ResultSet rs=stmt.executeQuery(sql);

               String str1 = 用户名输入.getText();
               String str2 = 密码输入.getText();
               System.out.println(str1);
               System.out.println(str2);
               String str3=null;
               String str4=null;
              while(rs.next())
               {
                   str3=rs.getString(1);
                   str4=rs.getString(2);
                   System.out.println(str3);
                   System.out.println(str4);
               }
             */String str1 = 用户名输入.getText();
               String str2 = 密码输入.getText();
               if(str1.equals("sims")&&str2.equals("504"))
               {
                   new Main();
               }
               else
                   JOptionPane.showMessageDialog(null,"你输入的用户名或密码有错误","登陆失败",JOptionPane.INFORMATION_MESSAGE);
        /*
           }  catch(Exception ee){}
        */

       }
        else if(e.getSource()==退出)
            System.exit(1);

   }

   public static void main(String []args)
   {
       new Login();
   }



}

⌨️ 快捷键说明

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