swt登录页面

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);
	}

}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值