java swt和jigloo的安装

一  SWT



从www.eclipse.org下载最新的eclipse,我下的是3.3,eclipse根据不同的操作系统分为不同的版本,在www.eclipse.org上已经表明清楚了,下载对应的操作系统下的eclipse就可以了。
然 后从http://download.eclipse.org/eclipse/downloads/drops/R-3.3-200706251500 /index.php下载 Example Plug-ins(注意,要下载对应的不同的eclipse版本,以下的一样),下载后直接解压缩,得到两个文件夹,features和plugins, 将对应的文件夹下的文件拷贝到eclipse下的文件夹内就可以了,然后再打开eclipse,file->new->example就可以 新建example工程了。
至于swt要分为两种,一种是swt例子的安装,一种是你自己的工程文件的安装,先说第一种:先去 http://download.eclipse.org/eclipse/downloads/drops/R-3.3-200706251500 /index.php下载 SWT Binary and Source,然后按照下面的步骤就可以了:
Adding SWT to your workspace

   1. Download SWT for standalone applications. A standalone version of SWT is available on the same download page as the Eclipse SDK. Look for the section titled SWT Binary and Source. Do not extract the archive file, just save it to disk.
   2. Select Import... from the File menu.
   3. Select Existing Projects into Workspace and click on the Next button.
   4. Select Select archive file: and use the Browse button to locate the SWT standalone archive you have previously downloaded.
   5. Click on the Finish button.

Importing example source

   1. Download and install the Eclipse Example Plug-ins. The Eclipse Example Plug-ins are available on the same download page as the Eclipse SDK. Look for the section titled Example Plug-ins. You can install the examples in the same location as you installed Eclipse or you can choose a different location. If you install the examples in the same location as Eclipse, the example views and editors will show up in your Eclipse environment (e.g. Windows > Show View ... > Other ... > SWT Examples If the SWT example views do not appear right away in your menu, restart eclipse with the -clean argument). This is fine but it is not necessary.
   2. Select New > Project ... from the File menu.
   3. Select Java Project and click on the Next button.
   4. Give the java project a name such as "SWT Examples".
   5. Select Create project from existing source and click on the Browse ... button to locate the following directory:     eclipse/plugins/org.eclipse.sdk.examples.source_3.1.0/src/org.eclipse.swt.examples_3.1.0
   6. Click on the Next button.
   7. Click on the Projects tab and click on the Add button.
   8. Place a check beside org.eclipse.swt and click on the OK button.
   9. Click on the Finish button.

At this point your SWT examples should be compiled without any errors. Check the Problems view for errors. If you get an error like "java.lang.Object not found" it means you have not configured a JRE. Go to the Window > Preferences ... dialog and select the Java > Installed JREs preference page. Ensure that a JRE is installed and that the path to the JRE is correct.
Running the Example

Now you can run the SWT standalone examples.

   1. Open the Java perspective.
   2. In the Packages view, select the main class that you want to run. For example, the main class for the Address Book example is org.eclipse.swt.examples.addressbook.AddressBook.
   3. Select Run > Run As... > Java Application from the main menu.


下面的是例子的运行:
From Eclipse's Window menu, select Show View > Other. In the Show View dialog, expand SWT Examples and select the SWT Example Launcher view. A view containing a list of examples will appear in your current perspective. When you select an example from the list a brief description of the example is displayed. Click on the Run button to launch the example.

通过以上步骤可以看出为什么要先安装example plugins再安装SWT例子了,要不然是看不到SWT例子的。

第二种主要是要环境设置,我参照了一种网上的方法:

第 一个需要的库是swt.jar文件,它位于ECLIPSE_HOME/eclipse/plugins /org.eclipse.swt.win32_2.1.0/ws/win32目录。根据你使用的Eclipse版本,你可能需要使用不同的目录。这个 swt.jar文件必须加到你的classpath中,为此在你的工程上点击右键,到 Project->Properies->JavaBuildPath->Libraries->Add Variable -> Eclipse Home ->Extend并按上述路径选择swt.jar库,然后单击OK。

然后,你可以编译 SWT应用程序,但是由于抛出下边所示的运行时异常(其实在我的程序里并没有出现以下的错误,不过为了以防以后可能会遇到,我还是记录下来,遇到了就设置 一下,没有的话就不用管它了),无法运行它,因为swt.jar使用了本地库。你需要设置java.library.path环境变量来在Java中使用 本地库。

Console output

java.lang.UnsatisfiedLinkError: no swt-win32-2133 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
...
at org.eclipse.swt.widgets.Display.<init>(Display.java:287)
at Main.main(Main.java:25)
Exception in thread "main"

要 设置java.library.path变量,到Run-> Run...-> Java Applicaton-> New ->Arguments -> VM Arguments。然后,如何需要,如下修改path,把它粘贴到VM Arguments部分。-Djava.library.path=c:/eclipse/plugins /org.eclipse.swt.win32_2.1.0/os/win32/x86,装载本地库

如果你需要装载应用程序使用的任何本地库,你可以使用Runtime.getPlatform.loadLibrary("libraryname")方法。

完成这些步骤,你就可以在你的eclipse环境下运行SWT程序了。

现在编写一个swt小程序:

工程的创建我就不再废话了,就用java project,程序如下:

import org.eclipse.swt.layout.RowLayout;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

 

public class SliderExample

{

  public static void main(String args[])

  {

 Display display = new Display();

 Shell shell = new Shell(display);

 shell.setLayout( new RowLayout());

    // ------------------------

    // Your code comes to here.

    // ------------------------

    shell.pack();

 shell.open();

 while( !shell.isDisposed())

    {

      if(!display.readAndDispatch())

      display.sleep();

    }

 display.dispose();

  }

}


这 个例子显示了一个空的窗口。你可以加widget到上边的模板。任何SWT应用程序需要 一个Display和一个或多个 Shells。这个Shell是个合成对象;它可以容纳其他的合成对象。如果没有设置shell的 layout,加到Shell的widget是不能看见的。Shell窗口必须 打开才能显示。 事件处理循环读取并转发GUI事件。如果没有事件处理循环应用程序窗口是无法显示的。即使通过open()方法来打开Shell窗口。让后,需要在 Shell被丢弃的时候销毁 Display。

好了,以上就设置完了,以后就可以了用swt编写java程序了,如果想要了解更多的swt功能和使用,可以到http://www.eclipse.org/swt/去找。

二   Jigloo


jigloo严格意义上来说也是收费的,不过他提供了non_commercial的版本,而这个版本的功能和commercial是完全一样的 http://www.cloudgarden.com/jigloo/。作为个人开发来说,是不受限制的。jigloo很小,最新的版本才3MB多,安 装也比较简单。

  jigloo同时支持SWT和Swing。

   jigloo也是完全基于Java代码的,不过它的code parse的能力远比VE要强,也要快。至少我很多在VE下出现问题,不能显示的Visual Class可以很好地在jigloo下编辑,至今还没有遇到jigloo不能编辑,parse出错的时候。而jigloo还可以集成了一写比较好的 Java GUI风格代码的支持,功能上比VE要强大一些。

    当然,3MB多的插件,再强也强不过SWT-Designer完整版的,但是比其基础版的要好很多。而SWT-Designer也并不是完全基于JAVA 开发的,比如Windows版本的,还携带了dll文件。而jigloo是完全基于JAVA开发的,下载下来只有一个class的zip文件,也支持 Eclipse的在线安装。


jigloo下载的地方很多去网上搜就是了,下载下来直接解压就可以了,网上很多说直接放到对应的文件夹就可以了,就像我上面example plugins的安装,可以我的就不可以,还要用links的办法。
1 在eclipse目录下创建一个links文件夹,在里面创建一个jigloo.link文件,内容为 path=/jigloo ,我用的是相对目录,然后在eclipse目录下创建一个jigloo文件夹,在里面再创建一个eclipse文件夹,将下载的jigloo.zip文件 解压后得到的features和plugins文件夹放到里面,然后重新打开eclipse,点击 File->New->Others->GUI Forms你就可以创建自己的SWT工程了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值