📄 passwordmodifydialog.java
字号:
package com.studentmanage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* velidate the password
* and reset the value
*/
public class PassWordModifyDialog extends Dialog
{
private Label lbInfo;
private Label label_2;
private Button btnCancel;
private Label label_1;
private Label label;
private Button tbnOK;
private Text txtPassWord2;
private Text txtPassWord1;
private Text txtPassWord;
protected Object result;
protected Shell shell;
/**
* Create the dialog
* @param parent
* @param style
*/
public PassWordModifyDialog(Shell parent, int style)
{
super(parent, style);
}
/**
* Create the dialog
* @param parent
*/
public PassWordModifyDialog(Shell parent)
{
this(parent, SWT.NONE);
}
/**
* Open the dialog
* @return the result
*/
public Object open()
{
createContents();
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.setSize(347, 251);
shell.setText("密码修改 ");
label = new Label(shell, SWT.NONE);
label.setText("初始密码:");
label.setBounds(49, 39, 56, 21);
lbInfo = new Label(shell, SWT.NONE);
lbInfo.setBounds(155, 105, 128, 19);
txtPassWord = new Text(shell, SWT.BORDER);
txtPassWord.setEchoChar('*');
txtPassWord.setBounds(124, 35, 161, 22);
txtPassWord1 = new Text(shell, SWT.BORDER);
txtPassWord1.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent arg0) {
lbInfo.setText("输入的密码位数:"+txtPassWord1.getText().length());
}
});
txtPassWord1.setEchoChar('*');
txtPassWord1.setBounds(124, 80, 161, 22);
label_1 = new Label(shell, SWT.NONE);
label_1.setBounds(49, 84, 56, 21);
label_1.setText("修改密码:");
txtPassWord2 = new Text(shell, SWT.BORDER);
txtPassWord2.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent arg0) {
lbInfo.setText("确认密码的位数:"+txtPassWord2.getText().length());
}
});
txtPassWord2.setEchoChar('*');
txtPassWord2.setBounds(124, 128, 161, 22);
label_2 = new Label(shell, SWT.NONE);
label_2.setBounds(49, 130, 56, 21);
label_2.setText("密码确认:");
tbnOK = new Button(shell, SWT.NONE);
tbnOK.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
//do these things when you click the button "确定"
//velidate the password
//把txtPassWord中的密码和初始密码比较
//把txtPassWord1和txtPassWord2种的密码比较
//修改成功
//
}
});
tbnOK.setText("确定");
tbnOK.setBounds(199, 170, 70, 25);
btnCancel = new Button(shell, SWT.NONE);
btnCancel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
shell.close();
shell.dispose();
}
});
btnCancel.setBounds(77, 171, 70, 25);
btnCancel.setText("放弃");
shell.setTabList(new Control[] {txtPassWord, txtPassWord1, txtPassWord2, tbnOK, btnCancel, label, label_1, label_2, lbInfo});
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -