📄 createpasswddialog.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 CreatePasswdDialog extends Dialog {
private Text reput;
private Text passwd;
private Button OK;
private Button cancel;
protected Object result;
protected Shell shell;
/**
* Create the dialog
* @param parent
* @param style
*/
public CreatePasswdDialog(Shell parent, int style) {
super(parent, style);
}
/**
* Create the dialog
* @param parent
*/
public CreatePasswdDialog(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.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setLayout(new FormLayout());
shell.setSize(247, 182);
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.right = new FormAttachment(100, -5);
fd_group.bottom = new FormAttachment(100, -5);
fd_group.left = new FormAttachment(0, 5);
fd_group.top = new FormAttachment(0, 0);
group.setLayoutData(fd_group);
final Label label = new Label(group, SWT.NONE);
label.setText("请输入密码:");
label.setBounds(10, 25, 74, 18);
passwd = new Text(group, SWT.BORDER);
passwd.setBounds(90, 22, 131, 18);
passwd.setEchoChar('*');
passwd.setFocus();
final Label label_1 = new Label(group, SWT.NONE);
label_1.setText("请再次输入:");
label_1.setBounds(10, 64, 74, 18);
reput = new Text(group, SWT.BORDER);
reput.setBounds(90, 61, 131, 18);
reput.setEchoChar('*');
OK = new Button(group, SWT.NONE);
OK.setText("确 定");
OK.setBounds(53, 107, 48, 22);
cancel = new Button(group, SWT.NONE);
cancel.setText("取 消");
cancel.setBounds(136, 107, 48, 22);
}
/*************************************************
************Register Listener *******************
*************************************************/
private void addListener(){
OK.addSelectionListener(OKSelection);
cancel.addSelectionListener(cancelSelection);
}
/*********************************************************
******************* Listener ****************************
*********************************************************/
/**
* 确定事件
*/
private SelectionListener OKSelection = new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
String password = passwd.getText().trim();
if(password.equals(reput.getText().trim())){
CDManager.action.setPassword(password);
MessageBox msgBox = new MessageBox(e.display.getShells()[0], SWT.ICON_INFORMATION
| SWT.OK);
msgBox.setText("成功");
msgBox.setMessage("创建密码成功!");
msgBox.open();
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();
reput.setText("");
return;
}
}
};
/**
* 取消事件
*/
private SelectionListener cancelSelection = new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
shell.dispose();
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -