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


PrevRetour IndexNext
  • But...
    Comment peut on utiliser une applet Java en interaction avec une page HTML (suite). Ou plus precisement comment appeler du code Java à partir d'un script JavaScript.

  • tmin_JS2.java : Source de l'applet...

  • source de l'applet
     // Importations
     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 ;
         }
         
      }


  • Comme vous pouvez le voir cela est vraiment tres simple....
    Dans ce cas l'utilisation de LiveConnect est totalement inutile.

  • Attention !! balise HTML : Pour pouvoir utiliser cela vous devez identifier votre applet au niveau du tag
    <APPLET codeBase="./" code=tmin_JS2 width=80 height=25 NAME=test1 >


  • Exemple d'utilisation : Javascript interaction



Copyright © 1996..2003, BERTHOU. Tous droits réservés.
Dernière modification le 03 Mars 2003 18H20

C.N.I.L.
n° 707410