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

📄 loginframe.java

📁 java课程的资料以及实验的代码
💻 JAVA
字号:
package com.hesj.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.hesj.mod.*;

public class LoginFrame extends JDialog{
	private  JLabel			jlName=new JLabel("UserName:");
	private  JTextField   	jtfUserName=new JTextField(7);
	
	private  JLabel			jlPass=new JLabel("PassWord:");
	private  JPasswordField jpfPassword=new JPasswordField(7);
	
	private  JButton        jbOk=new JButton("OK");
	private  JButton        jbCancel=new JButton("Cancel");
	
	private  Container       ct=this.getContentPane();
	
	public LoginFrame(){
		super();
		
		this.setSize(200,150);
		this.setTitle("Login Dialog");
		
		//show on  screen center
		Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation((int)(dim.getWidth()-this.getWidth())/2,
							(int)(dim.getHeight()-this.getHeight())/2);
							
		ct.setLayout(new FlowLayout());
		ct.add(jlName);
		ct.add(jtfUserName);
		ct.add(jlPass);
		ct.add(jpfPassword);
		ct.add(jbOk);
		ct.add(jbCancel);
	}
	
	//do event
	{
		doEvent();
	}
	
	public void doEvent(){
		this.jbOk.addActionListener(new ActionListener(){//login event
			public void actionPerformed(ActionEvent e){
				if(new LoginMod().login(jtfUserName.getText(),jpfPassword.getText())){
					//TODO: something for your Application
					dispose();
				}else{
					JOptionPane.showMessageDialog(null,"用户名或密码输入不正确");
				}
			}
		});
		
		this.jbCancel.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				jtfUserName.setText("");
				jpfPassword.setText("");				
			}
		});
	}
	
	public static void main(String[] args){
		new LoginFrame().setVisible(true);
	}
}

⌨️ 快捷键说明

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