###代码
package cn.haibin.rcp.test.oscblog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* 功能说明:基于SWT的单窗口演示程序
*
* @author cn.haibin
*
*/
public class SwtBtnHelloWorld {
public static void main(String[] args) {
final Display display = Display.getDefault();// Display多线程操作负责管理事件循环和控制UI线程和其它线程之间的通信
final Shell shell = new Shell(); // shell是程序的主窗口
shell.setSize(300, 200); // 设置主窗口的大小
shell.setText("HelloWorld"); // 设置主窗口的标题
//创建主窗口的其它界面组件
Button button = new Button(shell, SWT.NONE); //创建一个按钮对象
button.setText("HelloWorld"); //设置按钮文字
button.setBounds(100, 50, 100, 50); //设置按钮在窗体中位置和大小
shell.layout(); // 应用界面布局
shell.open(); // 打开shell主窗口
while (!shell.isDisposed()) {// 如果shell主窗口没有关闭,则一直循环
if (!display.readAndDispatch())
display.sleep(); // 如果display不忙,就让display处于休眠状态
}
display.dispose(); // 释放display资源
}
}
###运行结果 ###小结 不需要多说什么