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

📄 denglu.java

📁 这是一个接受用户名和密码实现登陆功能的GUI用户设计界面的程序
💻 JAVA
字号:
/*****************************************/
/*程序名:DengLu.java                      */
/*功  能:接受用户名和密码实现登陆功能           */
/*日  期:2008-02-28                      */
import java.awt.*;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class DengLu extends JFrame 
{
    private JTextField textField;
	private JPasswordField passwordField;
	//设置帐户和密码
	private String UserName = "123";
	private String UserPassword = "123";
	//设置计数器
	int count=1;
	JFrame frame;
	JOptionPane jOptionPane;
	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) 
	{
		try 
		{
			DengLu frame = new DengLu();
			frame.setVisible(true);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
/**
	 * Create the frame
	 */
	public DengLu() 
	{
		
		super("用户登陆界面");
	
		getContentPane().setLayout(null);
		setBounds(100, 100, 500, 375);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JPanel panel = new JPanel();
		panel.setBackground(Color.PINK);
		panel.setLayout(null);
		panel.setBounds(0, 0, 492, 348);
		getContentPane().add(panel);

		final JLabel label = new JLabel();
		label.setFont(new Font("", Font.BOLD, 14));
		label.setBounds(92, 61, 102, 33);
		panel.add(label);
		label.setText("用户名:");

		final JLabel label_1 = new JLabel();
		label_1.setFont(new Font("", Font.BOLD, 14));
		label_1.setText("密   码:");
		label_1.setBounds(92, 144, 135, 33);
		panel.add(label_1);

		passwordField = new JPasswordField();
		passwordField.setBounds(167, 144, 136, 31);
		panel.add(passwordField);

		textField = new JTextField();
		textField.setBounds(166, 61, 136, 33);
		panel.add(textField);

		final JButton button = new JButton();
		button.addMouseListener(new MouseAdapter()
		{
			public void mouseClicked(MouseEvent e) 
			{
				 //判断用户和密码是否正确,正确进入系统,不正确则三次后退出系统
				if((String.valueOf(passwordField.getPassword()).equals(UserPassword))&&(textField.getText().equals(UserName)))
				{
					JOptionPane.showMessageDialog(null, "登录成功");
					setVisible(false);
					frame.setVisible(true);
				}
		       if(count==1) 
		       {
					JOptionPane.showMessageDialog(null, "用户名或密码错误!");
					count++;
				}
				else if(count==2) 
				{
					JOptionPane.showMessageDialog(null, "用户名或密码错误!");
					count++;
				}
				else if(count==3) 
				{
					JOptionPane.showMessageDialog(null, "超出限制,登陆失败!");
					setVisible(false);
				}
			}
		});
		button.setFont(new Font("", Font.BOLD, 14));
		button.setText("登  陆");
		button.setBounds(63, 252, 115, 33);
		panel.add(button);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				System.exit(0);
			}
		});
		button_1.setFont(new Font("", Font.BOLD, 14));
		button_1.setText("取  消");
		button_1.setBounds(280, 252, 115, 33);
		panel.add(button_1);

	
	}

}

⌨️ 快捷键说明

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