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

📄 logindialog.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package eti.bi.alphaminer.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import eti.bi.alphaminer.core.handler.AccessController;

import eti.bi.common.Locale.Resource;


/**
 * LoginDialog is a JDialog shown to prompt for user login information.
 */
public class LoginDialog
	extends JDialog
	implements ActionListener, KeyListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	ApplicationWindow m_Container;

	private JPanel m_PanelLogin;
	private JPanel m_PanelContent;
	private JPanel m_PanelButton;

	private JPanel m_PanelLabel;
	private JPanel m_PanelInput;
	private JLabel m_LabelUsername;
	private JTextField m_Username;
	private JLabel m_LabelPassword;
	private JPasswordField m_Password;

	//<<20/01/2005, Frank J. Xu
	//To Adapt to Different Data Mining Engine
	private JLabel m_LabelDMEngineType;
	private JComboBox m_DMEngineType;
	private static String[] DM_ENGINE_TYPE = {"ETI DM", "SAS EM"};
	private String m_DMEngine = "ETI DM"; // Default is ETI DM
	//20/01/2005, Frank J. Xu>>
   
	private JButton m_ButtonOK;
	private JButton m_ButtonCancel;

	/**
	 * Constructs a LoginDialog
	 */
	public LoginDialog(Frame a_Frame) {
		super(a_Frame, "Login", true);
		m_Container = (ApplicationWindow) a_Frame;
		createLoginDialog();

		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setResizable(false);
		this.pack();
	}

	/**
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
		String message = null;

		if (e.getSource() == m_ButtonCancel) {
			this.dispose();
			return;
		}

		if (m_Username.getText().trim().equals("")
			|| m_Password.getPassword().length == 0)
			message = "Please enter both username and password.";
		else if (
			!AccessController.getInstance().login(
				m_Username.getText(),
				new String(m_Password.getPassword())))
			message =
				"Login failed! Incorrect username or password.\nPlease enter again.";
		else {
			this.dispose();
			//<<20/01/2005, Frank J. Xu
			//To Adapt to Different Data Mining Engine
			m_DMEngine = (String) m_DMEngineType.getSelectedItem();
			//20/01/2005, Frank J. Xu>>
			return;
		}

		JOptionPane.showMessageDialog(
			this,
			message,
			"AlphaMiner",
			JOptionPane.ERROR_MESSAGE);
		m_Username.requestFocus();
	}
	
	public String getDMEngine()
	{
		return m_DMEngine;
	}

	/**
	 * @see java.awt.event.KeyListener#keyPressed(KeyEvent)
	 */
	public void keyPressed(KeyEvent e) {
		if (e.getKeyCode() == KeyEvent.VK_ENTER)
			getFocusTraversalPolicy()
				.getComponentAfter(this, (JComponent) e.getSource())
				.requestFocus();
	}

	/**
	 * @see java.awt.event.KeyListener#keyReleased(KeyEvent)
	 */
	public void keyReleased(KeyEvent e) {
	}

	/**
	 * @see java.awt.event.KeyListener#keyTyped(KeyEvent)
	 */
	public void keyTyped(KeyEvent e) {
	}

	/**
	 * Creates the UI of LoginDialog.
	 */
	private void createLoginDialog() {
		m_PanelLogin = new JPanel(new BorderLayout(0, 0));
		m_PanelContent = new JPanel();
		m_PanelButton = new JPanel();

		m_PanelLabel = new JPanel(new GridLayout(3, 1));
		m_PanelInput = new JPanel(new GridLayout(3, 1));
		m_LabelUsername = new JLabel(Resource.srcStr("m_LabelUsername"));
		m_Username = new JTextField();
		m_LabelPassword = new JLabel(Resource.srcStr("m_LabelPassword"));
		m_Password = new JPasswordField();
		
		//<<20/01/2005, Frank J. Xu
		//To Adapt to Different Data Mining Engine"
		m_LabelDMEngineType = new JLabel(Resource.srcStr("m_LabelDMEngineType"));
		m_DMEngineType		= new JComboBox(DM_ENGINE_TYPE);
		//20/01/2005, Frank J. Xu>>
		
		m_ButtonOK = new JButton(Resource.srcStr("m_Button"));
		m_ButtonCancel = new JButton(Resource.srcStr("m_ButtonCancel"));

		m_PanelLogin.setPreferredSize(new Dimension(250, 120));
		m_PanelLabel.setPreferredSize(new Dimension(70, 75));
		m_PanelInput.setPreferredSize(new Dimension(145, 75));

		m_Username.setMargin(new Insets(2, 2, 2, 2));
		m_Username.setColumns(1);
		m_Password.setMargin(new Insets(2, 2, 2, 2));
		m_Password.setColumns(1);

		getContentPane().add(m_PanelLogin);
		m_PanelLogin.add(m_PanelContent, BorderLayout.CENTER);
		m_PanelLogin.add(m_PanelButton, BorderLayout.SOUTH);

		m_PanelContent.add(m_PanelLabel, null);
		m_PanelContent.add(m_PanelInput, null);

		m_PanelInput.add(m_Username, null);
		m_PanelInput.add(m_Password, null);
		m_PanelInput.add(m_DMEngineType, null);
		m_PanelLabel.add(m_LabelUsername, null);
		m_PanelLabel.add(m_LabelPassword, null);
		m_PanelLabel.add(m_LabelDMEngineType, null);

		m_PanelButton.add(m_ButtonOK, null);
		m_PanelButton.add(m_ButtonCancel, null);

		m_ButtonOK.setActionCommand("OK");
		m_ButtonCancel.setActionCommand("Cancel");

		m_Username.addKeyListener(this);
		m_Password.addKeyListener(this);
		m_ButtonOK.addActionListener(this);
		m_ButtonCancel.addActionListener(this);
	}
}

⌨️ 快捷键说明

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