SWT 学习入门--环境设置、编码、运行

时间:2021-01-10 22:23:45
SWT 学习入门--环境设置、编码、运行

SWT 学习入门--环境设置、编码、运行

 作者: 陈海青(josonchen,"船长")
(http://www.chq.name)
(http://www.hhrz.org)
(http://junit.vicp.net)
日期:2008.05.24 (yyyy.mm.dd)

一、开发环境设置:
(一)下载安装Eclipse
1:下载Eclipse,我下载的是3.2.1版(http://archive.eclipse.org/eclipse/downloads/drops/R-3.2.1-200609210945/eclipse-SDK-3.2.1-win32.zip
包含中文的语言包:http://eclipse.cdpa.nsysu.edu.tw/downloads/drops/L-3.2.1_Language_Packs-200609210945/NLpack1-eclipse-SDK-3.2.1-win32.zip
2:解压缩到某目录下,如D:javaeclipse-SDK-3.2.1-win32
3:下载java,如有没有的话
4:确定java的目录,如D:javajdk1.5.0_06in;没安装需要下载安装或解压缩
5:在桌面放置eclipse的快捷方式,修改其目标(target)为:D:javaeclipse-SDK-3.2.1-win32eclipseeclipse.exe -vm D:javajdk1.5.0_06jreinjavaw.exe
6:下载swt包(
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.3.2-200802211800/swt-3.3.2-win32-win32-x86.zip)和包含中文的语言包(The SWT Language Pack http://www.eclipse.org/swt/org.eclipse.swt.nl1_3.2.0.v200606220026.jar)
7: 下载安装Jigloo,用于图形化设计(http://cloudgarden1.com/jigloo_405.zip)

(二)运行Eclipse,切换到java透视图下面,从Package explore里面新建一个java project,例如命名为:Test,设置Build Path,在Libraries里面选择Add external JARs来添加运行SWT所需要的类库,这个和系统相关的,比如我在windows xp下,地址为:ECLIPSE_HOME/plugins/org.eclipse.swt.win32.win32.x86_3.2.1.v3235.jar。把它添加进来(建议可建一个variables指向这个swt.jar文件,以后直接添加variables就可以了)。

二、编写swt例程,如:
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
public class swt01 {
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();
}
}
三、设置运行
1、增加swt的jar:
在主菜单:projects--propertie--java Build path --Libraries里面选择Add external JARs来添加运行SWT所需要的类库,例如在windows xp下,假设地址为:D:eclipsepluginsorg.eclipse.swt.win32_3.0.0wswin32swt.jar。把它添加进来,建议做一个variables指向这个swt.jar文件,以后直接添加variables就可以了。
ECLIPSE_HOME/plugins/org.eclipse.swt.win32.win32.x86_3.2.1.v3235.jar
2.(使用 eclipse 3.3 或更新的版本可跳过此步骤)解压缩文件eclipsepluginsorg.eclipse.swt.win32.win32.x86_3.X.X.jar,释放以下文件到eclipseplugins根目录下:
o swt-awt-win32-XXXX.dll
o swt-gdip-win32-XXXX.dll
o swt-win32-XXXX.dll

3、从菜单run->run.... 切换到运行配置界面,选择Arguments在VM Arguments里面写入(假设在我的机器上DLL的地址为D:javaeclipse-SDK-3.2.1-win32eclipseplugins):
-Djava.library.path=D:javaeclipse-SDK-3.2.1-win32eclipseplugins

四、参考资料
1:http://www.blogjava.net/beansoft/archive/2007/03/18/104577.html
2:http://www.matrix.org.cn/resource/article/2008-05-06/e85ad221-1b2c-11dd-8f72-c7828c0f3f7c.html
3:http://www.eclipse.org/swt/eclipse.php
4: http://www.eclipse.org/swt/examples.php
5:http://www.cloudgarden.com/jigloo/
6:http://www.cloudgarden1.com/swt_tutorial/index.html

五、相关下载

1:http://www.chq.name/option,com_remository/Itemid,72/func,fileinfo/id_121.html
2:http://www.chq.name/option,com_remository/Itemid,72/func,fileinfo/id_122.html
3:http://www.chq.name/option,com_remository/Itemid,72/func,fileinfo/id_120.html
安装好后,把上述3中的jar包import到eclipse中即可

或者:
1:http://www.hhrz.org/option,com_remository/Itemid,72/func,fileinfo/id_121.html
2:http://www.hhrz.org/option,com_remository/Itemid,72/func,fileinfo/id_122.html
3:http://www.hhrz.org/option,com_remository/Itemid,72/func,fileinfo/id_120.html