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

📄 dengluchuangkou.txt

📁  用JAVA 写的一个小型的登陆窗口  使用密码和用户名来登陆
💻 TXT
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*; 


class Login extends JDialog implements ActionListener{
	
	int count=0;
	JPanel p0=new JPanel();
	JPanel p1=new JPanel();
	JPanel p2=new JPanel();
	JPanel p3=new JPanel();
	JTextField name=new JTextField(15);
	JPasswordField Password=new JPasswordField(15);
	JButton ok=new JButton("确定");
	JButton cancel=new JButton("取消");
	public Login(){
		setModal(true);
		setBackground(Color.blue);
		Container contentPane=this.getContentPane();
		contentPane.setLayout(new GridLayout(5,1));
		p1.add(new JLabel("用户名"));p1.add(name);
		p2.add(new JLabel("密  码"));p2.add(Password);
		p3.add(ok);p3.add(cancel);
		ok.addActionListener(this);
		cancel.addActionListener(this);
		name.addActionListener(this);
		Password.addActionListener(this);
		contentPane.add(p0);
		contentPane.add(p1);
		contentPane.add(p2);
		contentPane.add(p3);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(300,220);
		setTitle("登录窗口");
		setVisible(true);	
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==ok||e.getSource()==Password){
			if(name.getText().trim().equals("java")&&Password.getText().trim().equals("123")){
				dispose();
				new JframeFrame();
				
			}
			else{
				
				count++;
				if(count==3){
	
				JOptionPane.showMessageDialog(null,"非法用户");
				
				dispose();
				System.exit(0);
				}
				JOptionPane.showMessageDialog(null,"用户名或密码错误!");
				name.requestDefaultFocus();
				name.setSelectionStart(0);
				name.setSelectionEnd(name.getText().length());
			}
		
		}
		else if(e.getSource()==cancel){
			dispose();
			System.exit(0);	
		}
		
		
	}
	void creat(){
       	JDialog.setDefaultLookAndFeelDecorated(true);
       	
       	
       	
       	Font font=new Font("JFrame",Font.PLAIN,14);
        Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
        while(keys.hasMoreElements()){
        	Object key=keys.nextElement();
        	if(UIManager.get(key) instanceof Font)UIManager.put(key,font);
        	     
        }
       }
	public static void main(String[] args) {
        new Login();
	}
}

⌨️ 快捷键说明

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