JavaJSP Learning Series 13 (Applet call javascript function) (Translation)

zhaozj2021-02-16  53

The following example will explain the JavaScript function in the applet. A, applet source code (tmin_JS.java) // Importationsimport java.awt.Graphics; import java.awt.Event; // LiveConnect ... for JavaScriptimport netscape.javascript.JSObject; public class tmin_JS extends java.applet.Applet { // variables // initialisation de l'appletpublic void init () {// method init ()} // debiner l'AppleTPublic Void Paint (graphics g) {// method Paint () g.drawstring ("Click Here .. . ", 5, 10);} // mouse DownPublic Boolean MouseDown (Event E, INT X, INT Y) {Try {// Create JSObjectJsObject.getWindow (this) .eval (" JavaScript: alert ('Tmin_JS Click " "x =" x "y =" y ")");} catch (exception ex) {// error on create jsobjectshowstatus ("Error Call JavaScript Err =" EX);} Return True;} } Second, pay attention to the place (1) When calling the JavaScipt function, add this line: jsobject.getWindow (this). Eval ("JavaScript: ..."); (2) To put JSObject reference: import netscape .javascript.jsobject; (3) Defining applet When you add "MayScript" tag

转载请注明原文地址:https://www.9cbs.com/read-19782.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.044, SQL: 9