??? 作者:Flyingis
??? ArcEngine開發(fā)文檔中提供了另外一個開發(fā)簡例HelloGlobe,它是基于JFrame窗體的一個簡單應(yīng)用,從窗體設(shè)計(jì)代碼中我們可以看到,ArcEngine已經(jīng)以JavaBean的形式封裝了一些常用的窗體控件,可以直接的應(yīng)用到窗體設(shè)計(jì)的開發(fā)中,并且支持跨平臺,給開發(fā)者提供了另一種選擇。
??? 引用的包:
import?java.awt.BorderLayout;
import?java.awt.event.WindowAdapter;
import?java.awt.event.WindowEvent;
import?java.io.IOException;
import?javax.swing.JFrame;

import?com.esri.arcgis.beans.TOC.TOCBean;
import?com.esri.arcgis.beans.globe.GlobeBean;
import?com.esri.arcgis.beans.toolbar.ToolbarBean;
import?com.esri.arcgis.controls.ControlsGlobeFullExtentCommand;
import?com.esri.arcgis.controls.ControlsGlobeNavigateTool;
import?com.esri.arcgis.controls.ControlsGlobeOpenDocCommand;
import?com.esri.arcgis.system.AoInitialize;
import?com.esri.arcgis.system.EngineInitializer;
import?com.esri.arcgis.system.esriLicenseExtensionCode;
import?com.esri.arcgis.system.esriLicenseProductCode;??? 關(guān)于AWT和Swing的使用可以參考相關(guān)的書籍,從引用的包中,可以看到TOC、toolbar、globe顯示窗都已經(jīng)封裝到JavaBean中,可以直接調(diào)用,為開發(fā)者省了不少事,也幫助開發(fā)人員可以像在Visual Studio下設(shè)計(jì)UI一樣來設(shè)計(jì)Java的窗體。
??? 看看它的窗體設(shè)計(jì)代碼:
//
//?Create?and?display?the?frame
//

private?void?display()?throws?IOException?
{
??setSize(500,?400);
??//
??//?Create?the?globe,?toolbar,?and?table?of?contents?beans.
??//
??GlobeBean?globeBean?=?new?GlobeBean();
??ToolbarBean?toolbarBean?=?new?ToolbarBean();
??TOCBean?tocBean?=?new?TOCBean();
??//
??//?Add?beans?to?the?content?pane.
??//
??getContentPane().add(toolbarBean,?BorderLayout.NORTH);
??getContentPane().add(globeBean,?BorderLayout.CENTER);
??getContentPane().add(tocBean,?BorderLayout.WEST);
??//
??//?Add?commands?and?tool?to?the?toolbar.
??//
??toolbarBean.addItem(new?ControlsGlobeOpenDocCommand(),?0,?-1,?false,?0,?1);
??toolbarBean.addItem(new?ControlsGlobeNavigateTool(),?0,?-1,?false,?0,?1);
??toolbarBean.addItem(new?ControlsGlobeFullExtentCommand(),?0,?-1,?false,?0,?1);
??//
??//?Buddy?up?the?globe?with?the?toolbar?and?table?of?contents.
??//
??toolbarBean.setBuddyControl(globeBean);
??tocBean.setBuddyControl(globeBean);
??//
??//?Shutdown?ArcObjects?when?the?window?closes.
??//

??addWindowListener(new?WindowAdapter()?
{

????public?void?windowClosing(WindowEvent?e)?
{

??????try?
{
????????new?AoInitialize().shutdown();
????????System.exit(0);
??????}

??????catch?(IOException?ex)?
{
????????System.out.println(ex.getMessage());
????????System.exit(1);
??????}
????}
??});
??setVisible(true);
}
??? 純粹的Java窗體設(shè)計(jì)風(fēng)格,簡單易用。再看看main方法中的內(nèi)容,和前面一篇《AE92 SDK for Java 最小示例學(xué)習(xí)》稍有區(qū)別。
??? main方法:

public?static?void?main(String?args[])?
{

??try?
{
????EngineInitializer.initializeVisualBeans();????????????
????AoInitialize?aoInitializer?=?new?AoInitialize();
????aoInitializer.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
????aoInitializer.checkOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
????HelloGlobe?thisApp?=?new?HelloGlobe();
????thisApp.setTitle("Hello,?Globe!");
????thisApp.display();
??}

??catch?(IOException?ex)?
{
????System.out.println(ex.getMessage());
??}
}
??? 由于應(yīng)用程序使用了窗體,因此在原始AO組建和Java Class建立關(guān)聯(lián)時,需要initializeVisualBeans方法來初始化,initializeVisualBeans和initializeEngine兩者選其一,使用可視化Beans選擇前者,否則選擇后者。這里aoInitializer對象除了指定相應(yīng)的license授權(quán),還檢查相應(yīng)的應(yīng)用擴(kuò)展。
??? AE92 SDK for Java 已經(jīng)集成到Eclipse3.2中,通過ArcEngine模板建立一個HelloGlobe工程,看看運(yùn)行顯示的結(jié)果:

??? 基于這個模板框架,可以方便我們深入擴(kuò)展Globe二次開發(fā)的功能。