import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
public class SWTHello {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, SWT.NONE);
label.setText("Hello, World!");
shell.pack();
label.pack();
shell.open();
while(!shell.isDisposed())
if(!display.readAndDispatch())
display.sleep();
display.dispose();
label.dispose();
}
}
配置運行環境,由於SWT程式啟動並執行時候要用到本機資源,如果你現在運行上面的程式的時候會出現錯誤,類似於java.lang.UnsatisfiedLinkError: no swt-win32-2133 in java.library.path”,因此你必須指定所需的DLL的位置,具體做法是:從菜單run->run切換到回合組態介面,選擇Arguments在VM Arguments裡面寫入-Djava.library.path=例如在我的機器上DLL的地址為D:eclipsepluginsorg.eclipse.swt.win32_3.0.0oswin32†。這樣每次運行都要配置顯得有點麻煩,所以建議你在環境變數PATH裡面添加這個包括DLL的路徑。