helloworld.java

来自「Eclipse+SWTJFace开发实战精解 第一部分 基础概述篇」· Java 代码 · 共 34 行

JAVA
34
字号
package com.swtdesigner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class HelloWorld {
	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(236, 164);
		shell.setText("SWT Application");
		//定义一个文本框,样式风格为带边框
		final Text text = new Text(shell, SWT.BORDER);
		/**
		 * 对文本框进行在窗体上定位,通用模式为:
		 * setBounds(int x,int y,int width,int hight)
		 * x表示横坐标;y表示纵坐标;width表示文本框长度;
		 * hight表示文本框的高度
		 */
		text.setBounds(36, 37, 84, 21);
		//定义一个按钮
        final Button button = new Button(shell, SWT.NONE);
		button.setText("button");
		button.setBounds(134, 38, 57, 20);
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
}

⌨️ 快捷键说明

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