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

📄 authenticationhandler.java

📁 精通Jboss——Ejb和Web Services开发精解的随书源代码
💻 JAVA
字号:
/**
 * AuthenticationHandler.java Created on 2003-12-8
 *
 */
package com.liuyang.xmessenger.handler;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.liuyang.xmessenger.Actor;
import com.liuyang.xmessenger.impl.UserMessenger;

/**
 * @author liuyang
 *
 */
public class AuthenticationHandler extends JFrame implements ActionListener{
	
	private UserMessenger messager;
	/**
	 * @param messager
	 */
	public AuthenticationHandler(UserMessenger usermessager) {
		this();
		messager = usermessager;
	}
	public JTextField userfiled = new JTextField("用户名");
	public JTextField passfiled = new JTextField("密码");
	public boolean runing = true;
	
	public AuthenticationHandler(){
		
		this.getContentPane().setLayout(new BorderLayout());
		JButton loginbtn = new JButton("登陆");	
		loginbtn.addActionListener(this);
				
		this.getContentPane().add(BorderLayout.SOUTH,loginbtn);
				
		JPanel center = new JPanel();
		center.setLayout(new GridLayout(2,1));
		
		center.add(userfiled);	
		center.add(passfiled);	
		
		this.getContentPane().add(BorderLayout.CENTER,center);	
				
		this.pack();
		this.setSize(20,100);
		this.setLocation(210,150);		
		this.addWindowListener(
			new WindowAdapter(){
				public void windowClosing(WindowEvent event) {
					runing = false;
				}
			}
		);			
		this.setTitle("登陆窗口");	
		this.show();			
	}

	public boolean authenticate(Actor useractor){
		return false;
	}
	public static void  main(String[] args){
		AuthenticationHandler h = new AuthenticationHandler();
	}
	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
		String username = userfiled.getText();
		String password = passfiled.getText();
		boolean pass = false;
		try {
			pass = JMXClient.authenticate(username,password);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		if(messager!=null)
		messager.setAuthenticated(pass);
		if(pass){
			this.setVisible(false);
			Object o = messager.getHandler("login");
			if((o!=null)&&(o instanceof LogintHandler)){
				LogintHandler handler = (LogintHandler) o;
				handler.actionPerformed(null);
			}
		}
	}
}

⌨️ 快捷键说明

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