Java/jsp Learning Series 14 (JavaScript Change applet State) (translate)

Source: Internet
Author: User
JS The following example shows the use of JavaScript to change the applet state and invoke the method in the applet in JavaScript.

One, the 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 ' applets
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
Repaint ();
return;
}

Getstring:get String Value
Public String getString () {
return str;
}

Getval:get Number of change
public int Getval () {
return i;
}

}

Second, the attention of the place

(1) in the applet, to name:

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