RBL JAVA Tips
Main page
Home
[ Recherche | Home Page | Index Java tips ]


PrevRetour IndexNext
  • But...
    How can i used javascrip to communicate with a java applet.

  • tmin_JS.java : applet Source...

  • applet source
     // 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:alert('tmin_JS click " + 
    				" x=" + x + " y=" + y + "')") ; 
    	}
    	catch  (Exception  ex) {            // Error on create JSObject
    	    showStatus( "Error call javascript err=" + ex );
    	}
    	return true ;
         }
         
      }


  • Is very simple....
    You must use only 1 line to call Javascript function.
    JSObject.getWindow (this).eval ("javascript:... ") ;
    but don't forget JSObject import
    import netscape.javascript.JSObject ;


  • Warning !! HTML : To use javascript in an applet, you must be add "MAYSCRIPT" tag in applet definition
    <APPLET codeBase="./" code=tmin_JS width=80 height=25 MAYSCRIPT>


  • Exemple d'utilisation :
    Click here to see "javascript:alert" javascript:alert('tmin_JS click...')





Copyright © 1996..2003, BERTHOU. All right reserved.
Last change : 05 March 2003 18H20