loginframe.java

来自「java课程的资料以及实验的代码」· Java 代码 · 共 78 行

JAVA
78
字号
/*货物管理系统
 *设计者:任继梅/李爽/何双江/陈赓
 *用户登录模块
 **/
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())){
	     							dispose();
	     					new MFrame().show();
	     					
	     						
				}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 + =
减小字号Ctrl + -
显示快捷键?