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

📄 login.java

📁 java编写小型超市管理系统+数据库.用于小型超市简单的货品进存销
💻 JAVA
字号:
package com.wish;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Login extends JFrame implements ActionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JLabel a=new JLabel("用户名:");
	JLabel b=new JLabel("密        码:");
	JTextField admin_name=new JTextField(10);
	JPasswordField admin_pwd=new JPasswordField(10);
	ImageIcon ico= new ImageIcon("1.gif");
	JPanel ce=new JPanel();
	JPanel cb=new JPanel();
	JPanel cen=new JPanel();
	JButton login=new JButton("登录");
	JButton quit=new JButton("放弃");
	JPanel bottom =new JPanel();
	public Login(String title){
		super(title);
		ce.add(a);
		ce.add(admin_name);
		cb.add(b);
		cb.add(admin_pwd);
		cen.setLayout(new GridLayout(2,1));
		cen.add(ce);
		cen.add(cb);
		
		bottom.add(login);
		bottom.add(quit);
		//注册监听器
		login.addActionListener(this);
		quit.addActionListener(this);

		JLabel f=new JLabel("YY超市登陆",ico,JLabel.CENTER);
		f.setFont(new Font("隶书",1,30));
		
		this.getContentPane().add(f,BorderLayout.NORTH);
		this.getContentPane().add(cen);
		this.getContentPane().add(bottom,BorderLayout.SOUTH);
		setSize(300,210);
		setframe.set(this);

		admin_pwd.addKeyListener(new KeyAdapter(){
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode()==10)
					confirm();
			}
		});
	}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==login)
			confirm();
		else if(e.getSource()==quit)
			System.exit(0);
		else{return;}
	}
	//帐号确认函数
	private void confirm()
	{
		String admin_name=this.admin_name.getText();
		String admin_pwd=String.valueOf(this.admin_pwd.getPassword());
		boolean flag=new loginmanager().login(admin_name,admin_pwd);
		if(admin_name.equals("admin")&&flag==true)
		{
			this.dispose();
			
			new frame("管理界面");
		}
	else if(flag==true)
		{	
		this.dispose();
		new Saleframe("销售界面",this.admin_name.getText());
		}
	else
		JOptionPane.showMessageDialog(this,"错误的用户名或密码!");
	}
	public static void main(String args[])
	{new Login("登陆");}
}

⌨️ 快捷键说明

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