SWT程序示例,经典程序之第一个-- HelloWorld~~
运行效果如下:
- package com.swtjface.Ch2;
- import org.eclipse.swt.*;
- import org.eclipse.swt.widgets.*;
- /**
- * SWT入门的第一个程序
- *
- * @author 望江门外
- *
- */
- public class HelloSWT {
- public static void main(String[] args) {
- Display display = new Display(); // Display的作用主要用负责与操作系统的通信
- Shell shell2 = new Shell(display); // Shell用于显示窗口外观
- Text helloText = new Text(shell2, SWT.CENTER); // 文本框
- helloText.setText("Hello SWT~~"); // 设置文本框内容
- helloText.pack(); // 文本大小自动适应
- shell2.pack();
- shell2.open();
- while (!shell2.isDisposed()) {
- if (!display.readAndDispatch()) { // 不忙的时候,让display休眠
- display.sleep();
- }
- }
- display.dispose();
- }
- }