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

📄 inputpasswddialog.java

📁 CD Manager光盘资料管家婆源代码
💻 JAVA
字号:
package com.galaxyworkstation.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.galaxyworkstation.control.CDManager;


public class InputPasswdDialog extends Dialog {

	private Text passwd;
	protected Object result;
	protected Shell shell;
	
	private Button OK;
	private Button cancel;

	/**
	 * Create the dialog
	 */
	public InputPasswdDialog(Shell parent, int style) {
		super(parent, style);
	}

	/**
	 * Create the dialog
	 */
	public InputPasswdDialog(Shell parent) {
		this(parent, SWT.NONE);
	}

	/**
	 * Open the dialog
	 */
	public Object open() {
		createContents();
		addListener();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return result;
	}

	/**
	 * Create contents of the dialog
	 */
	protected void createContents() {
		shell = new Shell(getParent(), SWT.TITLE| SWT.APPLICATION_MODAL);
		shell.setLayout(new FormLayout());
		shell.setSize(231, 134);
		shell.setLocation((shell.getDisplay().getClientArea().width - shell.getClientArea().width) / 2,
				(shell.getDisplay().getClientArea().height - shell.getClientArea().height) / 2);
		shell.setText("请输入密码");

		final Group group = new Group(shell, SWT.NONE);
		final FormData fd_group = new FormData();
		fd_group.bottom = new FormAttachment(100, -5);
		fd_group.top = new FormAttachment(0, 0);
		fd_group.right = new FormAttachment(100, -5);
		fd_group.left = new FormAttachment(0, 5);
		group.setLayoutData(fd_group);

		final Label label = new Label(group, SWT.NONE);
		label.setText("请输入密码:");
		label.setBounds(10, 26, 81, 21);

		passwd = new Text(group, SWT.BORDER);
		passwd.setEchoChar('*');
		passwd.setBounds(92, 23, 111, 21);
		passwd.setFocus();
		
		OK = new Button(group, SWT.NONE);
		OK.setText("确  定");
		OK.setBounds(38, 64, 48, 22);

		cancel = new Button(group, SWT.NONE);
		cancel.setText("退  出");
		cancel.setBounds(111, 64, 48, 22);
		
	}
	
	/*************************************************
	 ************Register Listener *******************
	 *************************************************/
	private void addListener(){
		
		OK.addSelectionListener(okSelection);
		
		cancel.addSelectionListener(canceSelection);
	}
	
	/*********************************************************
	 ******************* Listener ****************************
	 *********************************************************/
	
	/**
	 * 确定事件
	 */
	private SelectionListener okSelection = new SelectionListener(){

		public void widgetDefaultSelected(SelectionEvent e) {
		}

		public void widgetSelected(SelectionEvent e) {
			
			if(passwd.getText().trim().equals(CDManager.action.getConfig().getPassword())){
				shell.dispose();
			}
			else{
				MessageBox msgBox = new MessageBox(e.display.getShells()[0], SWT.ICON_ERROR
						| SWT.OK);
				msgBox.setText("错误");
				msgBox.setMessage("您输入的密码错误,请重新输入!");
				msgBox.open();
				passwd.setText("");
				passwd.setFocus();
				return;
			}
		}
		
	};

	/**
	 * 取消事件
	 */
	private SelectionListener canceSelection = new SelectionListener(){

		public void widgetDefaultSelected(SelectionEvent e) {
		}

		public void widgetSelected(SelectionEvent e) {
		
			shell.getDisplay().getShells()[0].dispose();
		}
		
	};
}

⌨️ 快捷键说明

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