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 /**/ /**
7 * @author 糊涂鬼
8 * Created on 2005-8-9 16:05:23
9 */
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}
2 import org.eclipse.swt.widgets.Display;
3 import org.eclipse.swt.widgets.Label;
4 import org.eclipse.swt.widgets.Shell;
5
6 /**/ /**
7 * @author 糊涂鬼
8 * Created on 2005-8-9 16:05:23
9 */
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-3123 in java.library.path
Exception in thread "main"
解决方法则是找到两个 .dll 文件,分别叫:swt-awt-win32-3064.dll,swt-win32-3064.dll,把这两个东西复制到 win 系统目录下的 system32 ,相信大多数人还是用的 Windows 吧。
这样运行成功一次后好像就可以了,再删除的话也没什么关系,一样能够正常运行。
Swing 就不学了,谁让他没 SWT/JFace 强呢?既然是新学,就选功能最强大的开始吧。其实也挺可惜的,Swing 类库里的类我已经了解得有一定数目,并且使用起来问题也不是很大了。这样说丢就丢了,诶。