AE92 SDK for Java 窗体简例
发布日期:2021-09-03 20:14:06 浏览次数:2 分类:技术文章

本文共 3095 字,大约阅读时间需要 10 分钟。

   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
//
ExpandedBlockStart.gif
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.
  
//
ExpandedSubBlockStart.gif
  addWindowListener(
new WindowAdapter() {
ExpandedSubBlockStart.gif    
public 
void windowClosing(WindowEvent e) {
ExpandedSubBlockStart.gif      
try {
        
new AoInitialize().shutdown();
        System.exit(0);
      }
ExpandedSubBlockStart.gif      
catch (IOException ex) {
        System.out.println(ex.getMessage());
        System.exit(1);
      }
    }
  });
  setVisible(
true);
}

    纯粹的Java窗体设计风格,简单易用。再看看main方法中的内容,和前面一篇《》稍有区别。

    main方法:

ExpandedBlockStart.gif
public 
static 
void main(String args[])  {
ExpandedSubBlockStart.gif  
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();
  }
ExpandedSubBlockStart.gif  
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工程,看看运行显示的结果:

 

    基于这个模板框架,可以方便我们深入二次开发、扩展Globe的功能。

本文转自Flyingis博客园博客,原文链接:http://www.cnblogs.com/flyingis/archive/2007/03/09/669183.html,如需转载请自行联系原作者

转载地址:https://blog.csdn.net/weixin_34194702/article/details/90119769 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:GNU make manual 翻译(二十三)
下一篇:To Implement ZoomToSelection in Fusion Viewer MapGuide Enterprise 2011

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月04日 14时19分50秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章