Java/jsp Learning Series 13th (applet calls JavaScript Functions)

Source: Internet
Author: User
The following example shows how to call JavaScript Functions in the applet. 1. 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 ()
}

// 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;
}

}

Ii. Notes

(1) Add this line when calling the javascipt function:

Jsobject. getwindow (this). eval ("javascript :...");

(2) Reference jsobject:

Import Netscape. Javascript. jsobject;

(3) Add the mayscript mark when defining the applet.

<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.