18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BUILDING APPLICATIONS WITH VISUAL JAVABEANS<br />

import java.awt.event.WindowAdapter;<br />

import java.awt.event.WindowEvent;<br />

import java.io.IOException;<br />

import javax.swing.UIManager;<br />

import com.esri.arcgis.system.AoInitialize;<br />

import com.esri.arcgis.system.<strong>Engine</strong>Initializer;<br />

import com.esri.arcgis.system.esriLicenseProductCode;<br />

public class MapViewer {<br />

static {<br />

String laf = UIManager.getSystemLookAndFeelClassName();<br />

try {<br />

UIManager.setLookAndFeel(laf);<br />

} catch (Exception e) {<br />

// Ignore<br />

}<br />

}<br />

public static void main(String[] args) throws IOException {<br />

<strong>Engine</strong>Initializer.initializeVisualBeans();<br />

final AoInitialize aoInit = new AoInitialize();<br />

aoInit.initialize(<br />

esriLicenseProductCode.esriLicenseProductCode<strong>Engine</strong>);<br />

MapViewerFrame mapViewerFrame = new MapViewerFrame();<br />

Any application that uses visual JavaBeans<br />

components of the <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> Kit<br />

should include the following three JAR files in its<br />

class path:<br />

…\<strong>ArcGIS</strong>\java\opt\arcobjects.jar<br />

…\<strong>ArcGIS</strong>\java\opt\arcgis_ visualbeans.jar<br />

…\<strong>ArcGIS</strong>\java\jintegra.jar<br />

These files provide the runtime libraries needed<br />

for accessing ArcObjects from Java.<br />

When using a Java IDE, the class path is typically<br />

set by adding the above-mentioned JAR files as<br />

referenced libraries in the Java build path.<br />

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();<br />

int x = d.width/6;<br />

int y = d.height/6;<br />

int width = d.width*2/3;<br />

int height = d.height*2/3;<br />

mapViewerFrame.setBounds(x, y, width, height);<br />

mapViewerFrame.addWindowListener(new WindowAdapter() {<br />

public void windowClosing(WindowEvent e) {<br />

try {<br />

aoInit.shutdown();<br />

} catch (IOException ex) {<br />

ex.printStackTrace();<br />

}<br />

System.exit(0);<br />

}<br />

});<br />

mapViewerFrame.buildAndShow();<br />

}<br />

} // end MapViewer class<br />

3. At this stage you should be able to compile both the MapViewerFrame and<br />

MapViewer Java files. To do so, the Java compiler needs to be told where to<br />

find the referenced Java classes. This is done by specifying the class path.<br />

Chapter 6 • <strong>Developer</strong> scenarios • 307

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!