天天看點

SWT 入門之 -> HelloWorld

 1

SWT 入門之 -> HelloWorld

import org.eclipse.swt.SWT;

 2

SWT 入門之 -> HelloWorld

import org.eclipse.swt.widgets.Display;

 3

SWT 入門之 -> HelloWorld

import org.eclipse.swt.widgets.Label;

 4

SWT 入門之 -> HelloWorld

import org.eclipse.swt.widgets.Shell;

 5

SWT 入門之 -> HelloWorld

 6

SWT 入門之 -> HelloWorld
SWT 入門之 -> HelloWorld

10

SWT 入門之 -> HelloWorld
SWT 入門之 -> HelloWorld

public   class  HelloWorld 

SWT 入門之 -> HelloWorld

{

11

SWT 入門之 -> HelloWorld

12

SWT 入門之 -> HelloWorld
SWT 入門之 -> HelloWorld

    public static void main(String[] args) 

SWT 入門之 -> HelloWorld

{

13

SWT 入門之 -> HelloWorld

        Display display = new Display();

14

SWT 入門之 -> HelloWorld

        Shell shell = new Shell(display);

15

SWT 入門之 -> HelloWorld

        Label label = new Label(shell,SWT.CENTER);

16

SWT 入門之 -> HelloWorld

        label.setText("Hello, World!!");

17

SWT 入門之 -> HelloWorld

        label.setBounds(shell.getClientArea());

18

SWT 入門之 -> HelloWorld

        shell.open();

19

SWT 入門之 -> HelloWorld
SWT 入門之 -> HelloWorld

        while(!shell.isDisposed())

SWT 入門之 -> HelloWorld

{

20

SWT 入門之 -> HelloWorld
SWT 入門之 -> HelloWorld

            if(!display.readAndDispatch())

SWT 入門之 -> HelloWorld

{

21

SWT 入門之 -> HelloWorld

                display.sleep();

22

SWT 入門之 -> HelloWorld

            }

23

SWT 入門之 -> HelloWorld

            // 這裡是讓出來的控件停留一下,不加的話閃了一下後就消失了

24

SWT 入門之 -> HelloWorld
SWT 入門之 -> HelloWorld

            try 

SWT 入門之 -> HelloWorld

{

25

SWT 入門之 -> HelloWorld

                Thread.sleep(10000);

26

SWT 入門之 -> HelloWorld
SWT 入門之 -> HelloWorld

            } catch (InterruptedException e) 

SWT 入門之 -> HelloWorld

{

27

SWT 入門之 -> HelloWorld

                System.out.println(e.getMessage());

28

SWT 入門之 -> HelloWorld

            }

29

SWT 入門之 -> HelloWorld

            display.dispose();

30

SWT 入門之 -> HelloWorld

        }

31

SWT 入門之 -> HelloWorld

    }

32

SWT 入門之 -> HelloWorld

}

意圖很簡單的一個程式,因為是第一個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 類庫裡的類我已經了解得有一定數目,并且使用起來問題也不是很大了。這樣說丢就丢了,诶。