Autodesk 15606-011408-9300 Developer Guide - Page 42
Calling JavaScript Functions from a Java Applet, To access JavaScript from a Java Applet
UPC - 606121429548
View all Autodesk 15606-011408-9300 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 42 highlights
This code calls the Init function, which is placed within the onLoad event, which is inserted into the BODY tag. This prevents errors by loading the map before any code tries to access it. Init passes the embedded map object into the setMap function in the applet. Now you can make any API call to the example file, myUSAMap, in your applet. For instance: Public void getViewerInfo() { myUSAMap.aboutDlg(); } The API is available from Autodesk MapGuide classes in the npmapv32.zip file you copied in Step 1. Calling JavaScript Functions from a Java Applet You can call JavaScript functions in your HTML page from a Java applet. To access JavaScript from a Java Applet 1 Import the netscape.javascript package into your Java applet code. You can usually find this package in the \Program\Java\Classes\java40.jar file in the Netscape browser root directory. You can download this filw from http://developer.netscape.com/software/jdk/download.html. This package provides access to the JSObject class containing the getWindow method, which enables you to call JavaScript methods from your applet. 2 The syntax for calling a JavaScript function from your applet is: JSObject.getWindow(applet instance).call("function name", parameters) If you want to forward the onDigitizedCircle event to a JavaScript function called onDigitizedCircleHandler, you must first put all of the parameters into a java.lang.Object array before you can call onDigitizedCircleHandler. Since the fourth parameter of the onDigitizedCircle event is not derived from the java.lang.Object class, you need to wrap it as a java.lang.Double object: public void onDigitizedCircle(MGMap map, String units, MGPoint center, double radius) { Object[] params = new Object[4]; params[0] = map; params[1] = units; params[2] = center; params[3] = new Double(radius); JSObject.getWindow(this).call("onDigitizedCircleHandler", params); } 42 | Chapter 3 Accessing Maps