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(); } }
配置運(yùn)行環(huán)境,由于SWT程序運(yùn)行的時(shí)候要用到本機(jī)資源,假如你現(xiàn)在運(yùn)行上面的程序的時(shí)候會(huì)出現(xiàn)錯(cuò)誤,類似于java.lang.UnsatisfiedLinkError: no swt-win32-2133 in java.library.path”,因此你必須指定所需的DLL的位置,具體做法是:從菜單run->run切換到運(yùn)行配置界面,選擇Arguments在VM Arguments里面寫入-Djava.library.path=<folder containing the SWT DLL>例如在我的機(jī)器上DLL的地址為D:/eclipse/plugins/org.eclipse.swt.win32_3.0.0/os/win32/x86。這樣每次運(yùn)行都要配置顯得有點(diǎn)麻煩,所以建議你在環(huán)境變量PATH里面添加這個(gè)包括DLL的路徑。