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>