The following example will illustrate the JavaScript function in the applet

xiaoxiao2021-03-06  51

First, Applet Source Code (TMIN_JS.JAVA)

// Importations

Import java.awt.graphics;

Import java.awt.event;

// LiveConnect ... for JavaScript

Import Netscape.javascript.jsobject;

Public Class Tmin_JS Extends Java.applet.applet {

// Variables

// initialisation de l'applet

Public void init () {//Methode init ()

}

// debiner l'applet

Public void Paint (Graphics G) {//Methode Paint ()

g.drawstring ("Click Here ...", 5, 10);

}

// mouse down

Public Boolean MouseDown (Event E, INT X, INT Y) {

Try {// create jsobject

JSObject.getWindow (this). Eval ("JavaScript: ale

RT ('Tmin_JS Click "

"x =" x "y =" y ")");

}

Catch (Exception EX) {// Error On Create JSObject

ShowStatus ("Error Call JavaScript Err =" EX);

}

Return True;

}

}

Second, the attention of attention

(1) When calling the JavaScipt function, add this line:

JSObject.getWindow (this). Eval ("JavaScript: ...");

(2) To bring JSObject reference:

Import Netscape.javascript.jsobject;

(3) Tagging "MayScript" tag when defining applets

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

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