SWT程序示例,经典程序之第一个-- HelloWorld~~

    运行效果如下:

       

 
  
  1. package com.swtjface.Ch2; 
  2.  
  3. import org.eclipse.swt.*; 
  4. import org.eclipse.swt.widgets.*; 
  5.  
  6. /** 
  7.  * SWT入门的第一个程序 
  8.  *  
  9.  * @author 望江门外 
  10.  *  
  11.  */ 
  12. public class HelloSWT { 
  13.     public static void main(String[] args) { 
  14.  
  15.         Display display = new Display(); // Display的作用主要用负责与操作系统的通信 
  16.         Shell shell2 = new Shell(display); // Shell用于显示窗口外观 
  17.  
  18.         Text helloText = new Text(shell2, SWT.CENTER); // 文本框 
  19.         helloText.setText("Hello SWT~~"); // 设置文本框内容 
  20.         helloText.pack(); // 文本大小自动适应 
  21.  
  22.         shell2.pack(); 
  23.         shell2.open(); 
  24.         while (!shell2.isDisposed()) { 
  25.             if (!display.readAndDispatch()) { // 不忙的时候,让display休眠 
  26.                 display.sleep(); 
  27.             } 
  28.         } 
  29.         display.dispose(); 
  30.     }