package test1;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class SwtTest {
private Text text_1;
private Text text;
protected Shell shell;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
SwtTest window = new SwtTest();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
final Display display = new Display();
createContent();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.isDisposed();
}
private void createContent() {
shell = new Shell();
shell.setSize(411, 359);
shell.setText("登陆练习!");
text = new Text(shell, SWT.BORDER);
text.setBounds(197, 111, 142, 25);
text_1 = new Text(shell, SWT.BORDER | SWT.PASSWORD);
text_1.setBounds(197, 173, 142, 25);
final Button button = new Button(shell, SWT.ABORT);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
if (text.getText() != "" || text_1.getText() != "") {
MessageDialog.openInformation(shell, "登陆信息",
"欢迎" + text.getText() + "进入系统");
} else {
MessageDialog.openError(shell, "错误", "用户名密码为空,请重新输入");
}
}
});
button.setText("提交");
button.setBounds(85, 263, 48, 22);
final Button button_1 = new Button(shell, SWT.ABORT);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
shell.close();
}
});
button_1.setText("取消");
button_1.setBounds(274, 263, 48, 22);
final Label label = new Label(shell, SWT.NONE);
label.setText("用户名");
label.setBounds(113, 114, 36, 25);
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setText("密码");
label_1.setBounds(113, 176, 36, 25);
}
}
swt登录页面
最新推荐文章于 2021-09-25 15:12:56 发布