Flyingis

          Talking and thinking freely !
          Flying in the world of GIS !
          隨筆 - 156, 文章 - 16, 評論 - 589, 引用 - 0
          數據加載中……

          AE92 SDK for Java 窗體簡例

          ??? 作者:Flyingis

          ??? ArcEngine開發文檔中提供了另外一個開發簡例HelloGlobe,它是基于JFrame窗體的一個簡單應用,從窗體設計代碼中我們可以看到,ArcEngine已經以JavaBean的形式封裝了一些常用的窗體控件,可以直接的應用到窗體設計的開發中,并且支持跨平臺,給開發者提供了另一種選擇。

          ??? 引用的包:

          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;

          ??? 關于AWT和Swing的使用可以參考相關的書籍,從引用的包中,可以看到TOC、toolbar、globe顯示窗都已經封裝到JavaBean中,可以直接調用,為開發者省了不少事,也幫助開發人員可以像在Visual Studio下設計UI一樣來設計Java的窗體。

          ??? 看看它的窗體設計代碼:

          //
          //?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窗體設計風格,簡單易用。再看看main方法中的內容,和前面一篇《AE92 SDK for Java 最小示例學習》稍有區別。

          ??? 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());
          ??}

          }

          ??? 由于應用程序使用了窗體,因此在原始AO組建和Java Class建立關聯時,需要initializeVisualBeans方法來初始化,initializeVisualBeans和initializeEngine兩者選其一,使用可視化Beans選擇前者,否則選擇后者。這里aoInitializer對象除了指定相應的license授權,還檢查相應的應用擴展。

          ??? AE92 SDK for Java 已經集成到Eclipse3.2中,通過ArcEngine模板建立一個HelloGlobe工程,看看運行顯示的結果:

          HelloGlobe.gif

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

          posted on 2007-03-09 12:41 Flyingis 閱讀(4963) 評論(2)  編輯  收藏 所屬分類: ArcEngine

          評論

          # re: AE92 SDK for Java 窗體簡例[未登錄]  回復  更多評論   

          怎么設置toolbar的tip,我添加上toolbar后里面的按鈕全是英文的,怎么修改成中文?
          2008-01-10 09:20 | 王飛

          # re: AE92 SDK for Java 窗體簡例  回復  更多評論   

          ArcGIS Engine JAVA qq群: 24450639
          2009-02-22 17:49 | leagion
          主站蜘蛛池模板: 建瓯市| 景洪市| 屏山县| 张家界市| 临猗县| 柯坪县| 突泉县| 赫章县| 武威市| 江安县| 同德县| 会宁县| 焉耆| 海门市| 包头市| 鄱阳县| 大洼县| 扎赉特旗| 垣曲县| 中西区| 德保县| 温州市| 蒲城县| 福泉市| 萝北县| 定西市| 德庆县| 武乡县| 兴宁市| 平泉县| 惠东县| 靖远县| 根河市| 三穗县| 岢岚县| 通辽市| 武义县| 洮南市| 白城市| 南京市| 龙游县|