您的位置:首页 > 编程语言 > Java开发

AE92 SDK for Java 窗体简例

2007-05-19 14:51 225 查看
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工程,看看运行显示的结果:



基于这个模板框架,可以方便我们深入扩展Globe二次开发的功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: