早就聽(tīng)說(shuō)Eclipse的鼎鼎大名,瀏覽了好多關(guān)于Eclipse的文章,聽(tīng)說(shuō)用SWT,JFace能設計出擁有本地操作系統界面風(fēng)格的東東,如果在XP上運行,豈不是很讓客戶(hù)滿(mǎn)意,近期要做個(gè)桌面系統,^_^....., 想Trying 下.
用Eclipse當然就要裝上再說(shuō),這兩天我是吃勁了苦頭...,
下載了很多東西,讀了很多文章,終于調通了,現在給大家分享下.我沒(méi)有找到完整的安裝攻略,現在就寫(xiě)一個(gè)最新的..... 建議您先瀏覽下Eclipse網(wǎng)站
http://www.eclipse.org 尤其是 Projects 連接, 其中的Eclipse Projiect, 和 Eclipse Tools Project.
Eclipse (Eclipse SDK 最新的是3.0.2) 是一個(gè)平臺,其中的JDT,PDE都是集成在Eclipse
下載的,SWT,JFace開(kāi)發(fā)包也是,不用關(guān)心太多,有些文章說(shuō)的很多,反而讓新手迷惑...
Eclipse Tool Project 主要用到. Graphical Editor Framework (GEF) Project, EMF, VE
不要急于
下載這些東東,我算是吃勁苦頭......
用Eclipse當然希望用它的可視化
編程(Visual Edit Project) 插件. 現在最新的是 VE1.0.2.1
下載頁(yè)
http://www.eclipse.org/vep/現看它的
下載需求!!!!! 原來(lái)VE只能和相應版本的GEF,EMF,Eclipse SDK,一起工作,如果先前你
下載了其他的高版本,都糟踐的,關(guān)鍵是耽誤自己的時(shí)間.
好了,攻略開(kāi)始.建個(gè)
下載文件夾.
下載VE(1.0.2.1)
在同一個(gè)頁(yè)面的需求里
下載 Eclipse SDK 3.0.1, EMF 2.0.1, GEF3.0.1
解壓縮Eclipse SDK 3.0.1, 把解壓縮里的 eclipse 文件夾拷貝到D:\
看看里邊的內容,主要是plugins,features
解壓縮 EMF 到\emf 文件夾, 把emf\plugins 的東西都拷貝到d:\eclipse\plugins, emf\features 下的東西拷貝到d:\eclipse\features
VE,GEF 操作同上...
重要的,Eclipse 3.0.1 需要 JDK1.4.2, 所以要先安裝它.JDK的路徑設置就不再說(shuō)了.....\bin, \lib , \jdk1.4.2
由于運行SWT的程序用到本地庫,因此拷貝 D:\eclipse\plugins\org.eclipse.swt.win32_3.0.1\os\win32\x86 下的 *.dll 拷貝到 jdk路徑下的 \bin 目錄, 運行程序可以自動(dòng)找到. 這些問(wèn)題都困擾了我好長(cháng)時(shí)間.
現在啟動(dòng) d:\eclipse\eclipse.exe
^_^^_^,都OK了
eclipse 能自動(dòng)認出你的JRE.
實(shí)戰!
啟動(dòng)eclipse,看看welcome project 吧,不錯... 界面很迷人!
新建一個(gè)項目 file->New->project 出來(lái)項目向導, 選擇java project. ->next 輸入project Name:Hello Eclipse自動(dòng)給你建個(gè)workspace 工作文件夾,你的項目都存在這里的,d:\eclipse\workspace 點(diǎn)擊結束. 一個(gè)新項目建成了.
添加SWT ToolKit, 菜單Project->Properties 選擇左側的 Java Build Path 選擇 右側的 Libraries 標簽頁(yè), 點(diǎn)擊 Add Library 按鈕, 選擇 Standard Widget Toolkit(SWT) 點(diǎn)擊 Next , 選上 Include support for JFace library 結束.這樣就可以使用 SWT Jface控件了.
選中你的project Hello. 選擇新建圖標按鈕, 上端最左側的. 選擇 Visual Class ,點(diǎn)擊Next , Source Folder 是缺省的 project folder, package 填入 test, Name 填入 FrmHello , 展開(kāi)左側的 SWT 選擇 Shell, 勾選上 public static void main(String[] args), Constructors from superclass, Inherited abstract methods. 結束.
Eclipse自動(dòng)啟動(dòng) VE.... 看看那些窗口... 比較熟悉.. 出現了可視化編輯窗口.
鼠標移到右側的Palette(豎著(zhù)的那個(gè))把 一個(gè)Label,一個(gè)Button, 一個(gè)TextArea 放到shell上.
選中Label, 在下側的Properties屬性欄可以進(jìn)行設置, >text 填入Hello World
選中 Button 在下側的Properties屬性欄可以進(jìn)行設置, >text 填入Click Me.
選中 Button 右鍵, events->Add Events . 選擇Mouse - MouseAdapter ->mouseDown. 相應的代碼自動(dòng)產(chǎn)生.添加如下代碼(藍色部分)
也可進(jìn)行其他的風(fēng)格設置, 但是如果JDK版本不對則不能操作.有錯...
全部代碼:
/*
* Created on 2005-4-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package test;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
/**
* @author w19284
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class FrmHello {
private org.eclipse.swt.widgets.Shell sShell = null; // @jve:decl-index=0:visual-constraint="41,12"
private Label label = null;
private Button button = null;
private Text textArea = null;
/**
*
*/
public FrmHello() {
super();
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
/* Before this is run, be sure to set up the following in the launch configuration
* (Arguments->VM Arguments) for the correct SWT library path.
* The following is a
windows example:
* -Djava.library.path="installation_directory\plugins\org.eclipse.swt.win32_3.0.0\os\win32\x86"
*/
org.eclipse.swt.widgets.Display display = org.eclipse.swt.widgets.Display.getDefault();
FrmHello thisClass = new FrmHello();
thisClass.createSShell() ;
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep ();
}
display.dispose();
}
/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new org.eclipse.swt.widgets.Shell();
label = new Label(sShell, SWT.NONE);
button = new Button(sShell, SWT.NONE);
textArea = new Text(sShell, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
sShell.setText("Shell");
sShell.setBackground(org.eclipse.swt.widgets.Display.getDefault().getSystemColor(org.eclipse.swt.SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
label.setBounds(new org.eclipse.swt.graphics.Rectangle(167,5,96,24));
label.setText("Hello World");
label.setBackground(org.eclipse.swt.widgets.Display.getDefault().getSystemColor(org.eclipse.swt.SWT.COLOR_INFO_BACKGROUND));
label.setFont(new org.eclipse.swt.graphics.Font(org.eclipse.swt.widgets.Display.getDefault(), "Times New Roman", 12, org.eclipse.swt.SWT.BOLD));
button.setBounds(new org.eclipse.swt.graphics.Rectangle(152,34,123,24));
button.setText("Click Me");
button.setFont(new org.eclipse.swt.graphics.Font(org.eclipse.swt.widgets.Display.getDefault(), "Times New Roman", 14, org.eclipse.swt.SWT.NORMAL));
textArea.setBounds(new org.eclipse.swt.graphics.Rectangle(64,70,323,123));
sShell.setSize(new org.eclipse.swt.graphics.Point(451,232));
button.addMouseListener(new org.eclipse.swt.events.MouseAdapter() {
public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
System.out.println("mouseDown()"); // TODO Auto-generated Event stub mouseDown()
textArea.setText(textArea.getText() + "|Hello,Eclipse");
}
});
}
}
好了,大功馬上告成. 選擇運行圖標, toolBar 上的綠色按鈕旁邊的黑下箭頭.選擇->run.., 選擇左側的java Application 點(diǎn)擊下面的新建. 選擇中間Main標簽頁(yè), Project 選擇Hello , Main class: 選擇test.FrmHello. 點(diǎn)擊 run 按鈕.
界面出來(lái)了...., 以后你就可以直接點(diǎn)擊Run圖標,運行這個(gè)程序. 點(diǎn)擊Click Me 看看TextArea的變化...