import org.eclipse.swt.*;
  import org.eclipse.swt.widgets.*;
  public class SWTHello {
  public static void main(String[] args) {
  /*
  * Display的實(shí)例用于管理SWT與底層操作系統(tǒng)的連接,其
  * 最重要的功能是根據(jù)平臺(tái)的事件處理模型實(shí)現(xiàn)SWT的event
  * loop,一般來(lái)說(shuō),只要一個(gè)Display的實(shí)例就可以了。
  * 注意,在創(chuàng)建任何window前(Shell實(shí)例)需創(chuàng)建Display實(shí)例,
  * 在Shell實(shí)例關(guān)閉時(shí)除掉Display實(shí)例
  */
  Display display = new Display();
  
  /*
  *Shell是作為主窗口
  */
  Shell shell = new Shell(display);
  /*
  * SWT.NONE是Sytle bit,用于表明widget的style
  */
  Label label = new Label(shell,SWT.NONE);
  label.setText("Hello");
  shell.pack();
  label.pack();
  shell.open();
  while(!shell.isDisposed())
  {
  if(!display.readAndDispatch())
  display.sleep();
  }
  shell.dispose();
  }
  }
  
  關(guān)于Resource的Disposal
  1、如果你用構(gòu)造函數(shù)創(chuàng)建了widget或者graphic對(duì)象,當(dāng)你不需要時(shí)你必須手動(dòng)地dispose掉它;
  2、如果你不是使用構(gòu)造函數(shù)得到這個(gè)widget或者graphic對(duì)象,由于不是你allocate的,你不需要手動(dòng)來(lái)dispose掉它;
  3、如果你傳遞一個(gè)widget或者graphic對(duì)象的reference給另一個(gè)對(duì)象,那么你必須小心,不要在它仍在被使用中就dispose掉它;
  4、當(dāng)你close掉一個(gè)shell,那么這個(gè)shell及其子widget會(huì)被遞歸dispose掉的,雖然你不需再dispose掉那些widget,但是你必須free掉與這些widget相關(guān)的圖像資源;
  5、如果在一個(gè)widget的生命期中創(chuàng)建了graphic對(duì)象,可以通過(guò)注冊(cè)一個(gè)dispose listener來(lái)free這個(gè)graphic對(duì)象,不過(guò)數(shù)據(jù)對(duì)象如Rectangle和Point沒(méi)有使用操作系統(tǒng)資源,不用手動(dòng)dispose(它們也沒(méi)有dispose方法).