Java/jsp Learning Series 14th (JavaScript changes applet status)

Source: Internet
Author: User
The following example shows how to use JavaScript to change the applet status and call the method in the applet in Javascript.

1. Applet source code (tmin_js2.java)

// Import
Import java. AWT. graphics;
Import java. AWT. event;

// Liveconnect... for Javascript
// Not used... (it's more simple)

Public class tmin_js2 extends java. Applet. Applet {
// Variables
String STR; // sample string...
Int I; // Nb change...

// Initialisation de l' Applet
Public void Init () {// methode Init ()
STR = new string ("test ");
I = 0;
}

// Dessiner l' Applet
Public void paint (Graphics g) {// methode paint ()
G. drawstring (STR, 5, 10 );
}

// Setstring: change string value
Public void setstring (string s ){
STR = new string (s );
I ++;

// Force repaint to see change
Repaint ();
Return;
}

// Getstring: Get string value
Public String getstring (){
Return STR;
}

// Getval: get number of change
Public int getval (){
Return I;
}

}

Ii. Notes

(1) In the applet, name it:

<APPLET codebase = "./" code = tmin_js2 width = 80 Height = 25 name = test1>

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.