Java/jsp Learning Series 13 (applet calls JavaScript function) (translate)

Source: Internet
Author: User
Tags eval
The following example of the js| function shows the invocation of a JavaScript function in an applet. One, the 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 ' applets
public void init () {//Methode init ()
}

Dessiner 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 the place

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

Jsobject.getwindow (This). Eval (javascript: ...). ") ;

(2) to bring the Jsobject reference in:

Import Netscape.javascript.JSObject;

(3) When the applet is defined to add "Mayscript" Mark

<applet codebase= "./" Code=tmin_js width=80 height=25 mayscript>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.