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... (its more simple)
Public class tmin_JS2 extends java. applet. Applet {
// Variables
String str; // Sample string...
Int I; // nb change...
// Initialisation de lapplet
Public void init () {// Methode init ()
Str = new String ("test ");
I = 0;
}
// Dessiner lapplet
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>