??????????????????????????????????????????????????? SWT/Jface Step by Step(一)
????????????????????????????????????????????????????? Original Author:? 李紅軍 <lihongjun007@gmail.com>
重點介紹
SWT/JFACE
編程
,
主要介紹在
eclipse
下用
Windowbuilder
來開發
SWT/JFACE,
在這一篇中重點介紹幾個
eclipse
下常用的
GUI
插件
,
然后以一個
hello world
為例
,
在本文的后續文章中將會陸續給出更為詳細的介紹。
????????????? 本文中如果發現問題和錯誤,請隨時聯系筆者,以免誤導他人。
?????????????? 本文轉載不限,不過請保持本文完整。萬分感謝!
2006/07/08
Plugins? for? GUI? Introduction
?
l??????
SWT Designer :
可以從:
http://eclipse.openwebeng.com/downloads/drops/R-3.1-200506271435/swt-3.1-win32-win32-x86.zip
中下載到所需要的插件
l??????
Matisse GUI Builder
:適合于
NetBeans
下,不過在
eclipse?中
也可以使用。
Matisse For MyEclipse - 基于MyEclipse的Swing的可視化編輯器。
MyEclipse開發了一個開發swing程序的插件。
了解詳情請訪問:?http://myeclipseide.com/enterpriseworkbench/help/index.jsp?topic=/com.genuitec.eclipse.dehory.doc/doc/install/index.html
?
NetBeans
開發小組近日宣布,推出
NetBeans 5.0
新更新內容,
Matisse GUI Builder
。
此次更新的功能都將可以用在
NetBeans 6.0
開發環境中。
?
此次發布的新功能主要包括:
1. Automatic Internationalization
2. Visual Localization
3. Preview with Look and Feel
4. Relative Font Definition
5. Context Sensitive Help Bar
6. Reorganized Palette
?????????? ?????????7. Dragging Components from Projects Explorer
8. Support for Java 6 Layout
9. Bugfixes
可以從:
http://form.netbeans.org/JavaOne/
獲得下載更新。
?
l??????
Windowbuilder
:
WindowBuilder Pro v
v5.0.0
這是目前最新的版本,支持
Eclipse 3.1
和
Eclipse 3.2
,此軟件就是開發
Swt-Designer
和
Swing-Designer
公司的最新產品,它就是這兩種軟件的一個結合體(包含
Swt-Designer
和
Swing-Designer
最新專業版的所有功能),值得推薦!!!
我用的是
4.1.1
注冊版截圖
[
圖一
][
注意,注冊版的運行界面右上方沒有提示激活和購買的選項:


???????????????
圖一
下載地址:
http://www.instantiations.com/swt-designer/
大家可以根據自己的需要選擇對應的版本
破解補丁下載地址
[
注意對應相應的版本
]
:
WindowBuilder Pro For Eclipse 3.1 And 3.2 v4.1.1
注冊機
Keygen
http://soft.winzheng.com/SoftView/SoftView_28473.htm
基本上能總結的就是這么多了,如果大家還有什么問題,歡迎跟大家一起交流,以上過程在
Windows XP + J2SDK 1.5 + Eclipse 3.1.2
下調試成功。
eclipse
和
windowsBuilder
的安裝破解
:
1.??????
從
windowBuilder( http://www.instantiations.com/swt-designer)
下載與你的
eclipse
所對應的版本
2.
下載破解文件注冊
:
http://soft.winzheng.com/SoftView/SoftView_28473.htm
在
eclipse
安裝目錄下建立
links
文件夾,將
windowBuilder.start
放在此文件夾下,文件內容為插件的存放位置,插件可放在任意位置
.
用
agiwp411km.exe
生成注冊碼注冊
.
打開
eclipse
-
>Window
-
>Designer,
點擊
Registration and Activation
,選擇
WindowBuilder
,
Professional
。
next
,填寫資料,注意
Name
中名和姓要分開寫,如
hongjun li
。
next
,填入序列號和激活碼。
finished
!
NOTE:
???
我假定你在讀這篇文章的時候已經對Eclipse有所了解,所以不會解釋到具體Eclipse如何使用。
????????
Contact me
如果你希望和我聯系的話,你可以發
email
到
lihongjun007@gmail.com
。
我的
blog
:
http://m.tkk7.com/hongjunli/
Important
如果你不知道什么是
eclipse
?你可以打開
http://www.eclipse.org/
,這是
eclipse
的官方站點。
你不知道什么是
Swt/JFace,
你可以讀一下《
eclipse in action
》這本書。
?
A Simple Demo!
?
下面的內容就是我們的
Demo
示例。首先建立一個類,我將這個類取名為
MyFrame
,在我的
SWT
工程中,它位于
net.itpub.hongjunli
包的下面。類的內容如下:
package net.itpub.hongjunli;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
?
public class MyFrame {
?
??? /**
???
?* Launch the application
???
?* @param args
???
?*/
??? public static void main(String[] args) {
???????????? //
獲得
display
類型的對象
???????????? final Display display = Display.getDefault();
???????????? //
構造程序的主窗口
???????????? final Shell shell = new Shell();
???????????? //
設置主窗口的大小
???????????? shell.setSize(426, 245);
???????????? //
設置主窗口的標題,顯示
Hello, Hongjun
???????????? shell.setText("Hello, Hongjun ");
???????????? //
打開豬窗口
???????????? shell.open();
???????? //
設置文本框的文字、字體以及大小
???????????? final Text thisIsMyText = new Text(shell, SWT.BORDER);
???????????? thisIsMyText.setText("This is my first designer");
???????????? thisIsMyText.setBounds(67, 35, 170, 27);
??????? //
設置按鈕的標簽文字、大小及位置
???????????? final Button button = new Button(shell, SWT.NONE);
???????????? button.addSelectionListener(new SelectionAdapter() {
?????????????????????? public void widgetSelected(SelectionEvent e) {
?????????????????????? }
???????????? });
???????????? button.setText("Begin");
???????????? button.setBounds(32, 103, 71, 37);
???????????? button.addSelectionListener(new SelectionAdapter() {
?????????????????????? //
如果單擊按鈕事件發生之后
?????????????????????? public void widgetSelected(SelectionEvent e) {
?????????????????????? //
改變文本框中顯示的文本信息
??????????????????????????????? thisIsMyText.setText("
你單擊了
Begin
按鈕
");
???????????????????????????????
?????????????????????? }
???????????????????????????????????????? });
???????????? final Button button_1 = new Button(shell, SWT.NONE);
???????????? button_1.addSelectionListener(new SelectionAdapter() {
?????????????????????? //
如果單擊按鈕事件發生之后
?????????????????????? public void widgetSelected(SelectionEvent e) {
?????????????????????? //
改變文本框中顯示的文本信息
??????????????????????????????? thisIsMyText.setText("
你單擊了
End
按鈕
");
???????????????????????????????
?????????????????????? }
??????????????????????
??????????????????????
???????????? });
???????????? button_1.setText("End");
???????????? button_1.setBounds(190, 97, 75, 43);
???????????? //
設置主窗口的布局
???????????? shell.layout();
???????????? //if display
不運行,則讓
display
休眠
???????????? while (!shell.isDisposed()) {
?????????????????????? if (!display.readAndDispatch())
??????????????????????????????? display.sleep();
???????????? }
??? }
}
代碼段
1
關于這段代碼的內容,我們會在下面的內容中進行詳細介紹。現在我們可以嘗試著運行一下,確定已經編譯完成后從
eclipse
的
Package Explorer
中選中這個類然后點右鍵,在彈出的菜單中你會看到
Run As
,進一步選中這一項,然后在級聯菜單中選
“Run As SWT Application”
,如果運行正常的話你會看到如圖
2
的運行結果:

???????????
圖二
?
????????????????????????????????????????CONTINUE