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

📄 login.java

📁 丽婴房库存销售系统 描述:C/S构架
💻 JAVA
字号:
package src1;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class Login extends JFrame implements ActionListener{

	/**
	 * 
	 */
	private JButton bt1,bt2;
	private JTextField id=null;
    private JPasswordField pw=null;
    private int widthS = Toolkit.getDefaultToolkit().getScreenSize().width;
	private int heightS = Toolkit.getDefaultToolkit().getScreenSize().height;
	private int width = 500;
	private int height =400;
	private int X =(widthS-width)/2;
	private int Y =(heightS-height)/2;
	private JLabel label =new JLabel("丽婴房库存管理系统");
	private JLabel label2;
	String idText;
	String pwText;
	String sql;
	private ResultSet rset=null;
	private ConSqlServer con ;
	private int i;
	
	public Login()
	{
		super("登录窗口");
		this.setBackground(new Color(240,250,255));
	   
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(X,Y,width,height);
		
		label.setBounds(125,30,500,100);
		label.setFont(new Font("隶书",Font.CENTER_BASELINE,28));
		label.setForeground(Color.blue);
		label2 = new JLabel();
		label2.setBounds(135,0,500,30);
		label2.setIcon(new ImageIcon("./src/icons/45.gif"));
		
		JPanel panel =new JPanel();
		panel.setLayout(null);
		panel.setBounds(155,150,180,160);
		panel.setBackground(new Color(240,250,255));
		Container cp=this.getContentPane();
		cp.setLayout(null);
		cp.setBackground(new Color(240,250,255));
		
		JLabel user=new  JLabel("用户名:");
		JLabel pword=new JLabel("密   码:");
		bt1=new JButton("确定");
        bt2=new JButton("取消");
        
        user.setIcon(new ImageIcon("./src/icons/37.gif"));
        pword.setIcon(new ImageIcon("./src/icons/32.gif"));
        bt1.setIcon(new ImageIcon("./src/icons/39.gif"));
        bt2.setIcon(new ImageIcon("./src/icons/38.gif"));
        
         pw=new JPasswordField();
         id=new JTextField(12);      
      
       
        user.setBounds(0, 0,80,25);
		id.setBounds(80, 0, 100, 25);
		
	    pword.setBounds(0, 55,80,25);
		pw.setBounds(80, 55, 100, 25);
		bt1.setBounds(new Rectangle(0, 110, 80, 30));
		bt2.setBounds(new Rectangle(100, 110, 80, 30));
		
		panel.add(user);
		panel.add(pword);
		panel.add(id);
		panel.add(pw);
		
		panel.add(bt1);
		panel.add(bt2);	
		
		panel.setVisible(true);
		cp.add(label);
		cp.add(panel);
		
		
		
	    bt1.addActionListener(this);
		bt2.addActionListener(this);
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		
		if(e.getSource()==bt1)
		{
			System.out.println("    ok      ");
			getUserName();
			getPassWord();
		    sql="SELECT * FROM users WHERE id= '" +
			idText + "' AND pw='" + pwText+ "';";
		    con = new ConSqlServer();
		    rset = con.executeQuery(sql);
		    isSuccessLogin();
		    con.close();
			
		}
		if(e.getSource()==bt2)
		{
			id.setText("");
			pw.setText("");
		}
	}
	private void isSuccessLogin()
	{
		
		try {
			 
	    	if(rset.next()){
	    		System.out.println(MainForm.adminOrMember = rset.getInt("adminOrMember"));
	    		new MainForm().addWindowListener(new WindowAdapter()
		        {
		        	public void windowClosing(WindowEvent ex)
		    		{
		        		
		        		
		        		System.exit(0);
		        		
		    		}
		        
		        }	);
	    		this.setVisible(false);
				//JOptionPane.showMessageDialog(null, "登录成功","提示信息",JOptionPane.INFORMATION_MESSAGE);
			
			}else{
				i++;
				if(i>4){JOptionPane.showMessageDialog(null, "你已输入了五次错误信息,不能再登录","提示信息",JOptionPane.ERROR_MESSAGE);
				//hread.sleep(10);
				
				}
				else {
					JOptionPane.showMessageDialog(null, "用户名或密码错误","提示信息",JOptionPane.ERROR_MESSAGE);
					pw.setText("");
				}
			}
		
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
	}
	private void getUserName()
	{
		 idText=id.getText().trim();
	}
	private  void getPassWord()
	{
		
		
		 pwText=String.copyValueOf(pw.getPassword());
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Login();
		
		

	}

}

⌨️ 快捷键说明

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