1

import org.eclipse.swt.SWT;
2

import org.eclipse.swt.widgets.Display;
3

import org.eclipse.swt.widgets.Label;
4

import org.eclipse.swt.widgets.Shell;
5

6
10
public class HelloWorld
{
11
12
public static void main(String[] args)
{
13
Display display = new Display();
14
Shell shell = new Shell(display);
15
Label label = new Label(shell,SWT.CENTER);
16
label.setText("Hello, World!!");
17
label.setBounds(shell.getClientArea());
18
shell.open();
19
while(!shell.isDisposed())
{
20
if(!display.readAndDispatch())
{
21
display.sleep();
22
}
23
// 這裡是讓出來的控件停留一下,不加的話閃了一下後就消失了
24
try
{
25
Thread.sleep(10000);
26
} catch (InterruptedException e)
{
27
System.out.println(e.getMessage());
28
}
29
display.dispose();
30
}
31
}
32
}
意圖很簡單的一個程式,因為是第一個SWT程式嘛,就這樣運作的話是會抛出異常的:
java.lang.UnsatisfiedLinkError: no
swt-win32-3123in java.library.path
Exception in thread "main"
解決方法則是找到兩個 .dll 檔案,分别叫:swt-awt-win32-3064.dll,swt-win32-3064.dll,把這兩個東西複制到 win 系統目錄下的 system32 ,相信大多數人還是用的 Windows 吧。
這樣運作成功一次後好像就可以了,再删除的話也沒什麼關系,一樣能夠正常運作。
Swing 就不學了,誰讓他沒 SWT/JFace 強呢?既然是新學,就選功能最強大的開始吧。其實也挺可惜的,Swing 類庫裡的類我已經了解得有一定數目,并且使用起來問題也不是很大了。這樣說丢就丢了,诶。