Différences entre versions de « Référence:JavaScript »

De GeoGebra Manual
Aller à : navigation, rechercher
Ligne 5 : Ligne 5 :
  
  
= Examples =
+
= Exemples =
Example 1: the following HTML code fragment adds a "Reset" button to an HTML page that lets the user reset the construction shown in the GeoGebraApplet to its initial state:
+
Exemple 1 : le fragment de code HTML suivant ajoute un bouton "Réinitialiser" dans une page HTML, ce qui permet à l’utilisateur de ramener la  construction affichée par GeoGebra dans son état initial :
 +
<form>
 +
<input type="button" value="Réinitialiser" onclick="document.applets[0].reset();">
 +
</form>
  
  <form>
 
    <input type="button" value="Reset" onclick="document.applets[0].reset();">
 
  </form>
 
  
Example 2: this adds two buttons "Hide A" and "Show A" change the visibility state of an object named "A" in the construction
+
Exemple 2 : celui-ci ajoute deux boutons "Cacher A" et " Afficher A" pour changer l’état d’affichage de l’objet nommé “A" dans la construction
 +
<form>
 +
<input type="button" value="Cacher A" onclick="document.applets[0].setVisible('A', false);">
 +
<input type="button" value="Afficher A" onclick="document.applets[0].setVisible('A', true);">
 +
</form>
  
  <form>
 
    <input type="button" value="Hide A" onclick="document.applets[0].setVisible('A', false);">
 
    <input type="button" value="Show A" onclick="document.applets[0].setVisible('A', true);">
 
  </form>
 
  
Example 3: a JavaScript function "myLittleConstruction()" is used to call several methods of the GeoGebraApplet. Note: the language is set to German ("de") with the applet parameter "language" in the applet tag in order to make sure that the German command "Gerade" (line) will work.
+
Exemple 3: Une fonction JavaScript "maConstruction()" est utilisée pour appeler plusieurs méthodes de l’appliquette GeoGebra. Note : La langue est fixée à Français ("fr") avec le paramètre "language" dans la balise de l’appliquette afin de faire en sorte que la commande française "Droite" fonctionne.
 +
<applet name="ggbApplet" code="geogebra.GeoGebraApplet"
 +
        archive="geogebra.jar"
 +
        width=200 height=40>
 +
    <param name ="fileNom" value="circle.ggb">
 +
    <param name ="framePossible" value="false">
 +
    <param name ="language" value="fr">
 +
    <a href="http://www.java.com"> Installez  Java 1.4.2</a> (ou supérieure) pour utiliser cette  page.
 +
</applet>
 +
<script type="text/javascript">
 +
function maConstruction() {
 +
var applet = document.ggbApplet;
 +
applet.evalCommand("A = (1,1)"); 
 +
applet.evalCommand("B = (3,2)")
 +
applet.evalCommand("s = Droite[A, B]"); 
 +
}
 +
</script>
 +
<form>
 +
<input type="button" value="Faire la construction" onclick="maConstruction();">
 +
</form>
  
  <applet name="ggbApplet" code="geogebra.GeoGebraApplet"
 
    archive="geogebra.jar"
 
    width=200 height=40>
 
  <param name="filename" value="circle.ggb">
 
  <param name="framePossible" value="false">
 
  <param name="language" value="de">
 
  Please <a href="http://www.java.com">install Java 1.4.2</a> (or later) to use this page.
 
  </applet>
 
  <script type="text/javascript">
 
    function myLittelConstruction() {
 
      var applet = document.ggbApplet;
 
      applet.evalCommand("A = (1,1)");
 
      applet.evalCommand("B = (3,2)");
 
      applet.evalCommand("s = Gerade[A, B]");
 
    }
 
  </script>
 
  <form>
 
    <input type="button" value="Do construction" onclick="myLittelConstruction();">
 
  </form>
 
  
Example 4: Have a look at the source code of the following example worksheet that uses JavaScript.
+
Exemple 4: Have a look at the source code of the following example worksheet that uses JavaScript.
 
   http://www.geogebra.org/source/program/applet/geogebra_applet_javascript_test.htm
 
   http://www.geogebra.org/source/program/applet/geogebra_applet_javascript_test.htm
  
Example 5: This is an example worksheet that uses an ''add listener'' to check when a particular construction has been completed (and then says "Well done").
+
Exemple 5: This is an example worksheet that uses an ''add listener'' to check when a particular construction has been completed (and then says "Well done").
 
   http://www.geogebra.org/en/examples/javascriptAutomaticCheckingExercise.html
 
   http://www.geogebra.org/en/examples/javascriptAutomaticCheckingExercise.html
  
= Available Methods =
+
= Méthodes utilisables =
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
 
     <tr>
 
     <tr>
 
       <th>Méthode</th>
 
       <th>Méthode</th>
      <th style="text-align: center;">Since</th>
 
 
       <th>Description</th>
 
       <th>Description</th>
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
 
       <td>evalCommand(commande)</td>
 
       <td>evalCommand(commande)</td>
      <td style="text-align: center;">3.0</td>
 
 
       <td>Évalue la chaîne comme si vous l’aviez entrée dans le champ de saisie  [ex : evalCommand('s = Droite[A, B]')].  <br> Vous pouvez utiliser plusieurs commandes en les séparant par "\n"<br>Note : Utilisez le paramètre “language” [[Reference:Applet_Parameters|language parameter]] pour vous assurez que la commande de votre langue est reconnue.<br>
 
       <td>Évalue la chaîne comme si vous l’aviez entrée dans le champ de saisie  [ex : evalCommand('s = Droite[A, B]')].  <br> Vous pouvez utiliser plusieurs commandes en les séparant par "\n"<br>Note : Utilisez le paramètre “language” [[Reference:Applet_Parameters|language parameter]] pour vous assurez que la commande de votre langue est reconnue.<br>
 
       </td>
 
       </td>
Ligne 62 : Ligne 60 :
 
     <tr>
 
     <tr>
 
       <td>void setUndoPoint()</td>
 
       <td>void setUndoPoint()</td>
      <td style="text-align: center;">3.2</td>
 
 
       <td> Sets an undo point. Useful if you want the user to be able to undo that action of evalCommand eg if you have made an HTML button to act as a custom tool<br>
 
       <td> Sets an undo point. Useful if you want the user to be able to undo that action of evalCommand eg if you have made an HTML button to act as a custom tool<br>
 
       </td>
 
       </td>
Ligne 81 : Ligne 78 :
 
     <tr>
 
     <tr>
 
       <th>Méthode</th>
 
       <th>Méthode</th>
      <th style="text-align: center;">Since</th>
 
 
       <th>Description</th>
 
       <th>Description</th>
 
     </tr>
 
     </tr>
Ligne 139 : Ligne 135 :
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setLineStyle(String objName, int style)</td>
+
       <td>setLineStyle(nom,entier)</td>
      <td style="text-align: center;">3.2</td>
+
       <td>Définit le style du trait (de 0 à 4)</td>
       <td>Sets the line style for the object (0 to 4)</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setLineThickness(String objName, int thickness)</td>
+
       <td>setLineThickness(nom,entier)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Définit l’épaisseur de l’objet (de 1 à 13) (1 par défaut)</td>
      <td>sets the thickness of the object (1 to 13, -1 for default)</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setPointStyle(String objName, int style)</td>
+
       <td>setPointStyle(nom,entier)</td>
      <td style="text-align: center;">3.2</td>
+
       <td>Définit le style du point (-1 par défaut, 0 disque, 1 cercle, 2 croix,3 plus, 4 diamant plein, 5 diamant vide, 6 triangle (nord), 7 triangle (sud), 8 triangle (est), 9 triangle (ouest))</td>
       <td>Sets the style of points (-1 default, 0 filled circle, 1 circle, 2 cross, 3 plus, 4 filled diamond, 5 unfilled diamond, 6 triangle (north), 7 triangle (south), 8 triangle (east), 9 triangle (west))</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setPointSize(String objName, int size)</td>
+
       <td>setPointSize(nom,entier)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Définit la taille du point (de 1 à 9)</td>
      <td>Sets the size of a point (from 1 to 9)</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setFilling(String objName, double filling)</td>
+
       <td>setFilling(nom,nombre)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Définit le remplissage de l’objet (de 0 à 1)</td>
      <td>Sets the filling of an object (from 0 to 1)</td>
 
 
     </tr>
 
     </tr>
 
</table>
 
</table>
  
==Automatic Animation==
+
==Animation automatique==
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
 
     <tr>
 
     <tr>
       <th>Method Signature</th>
+
       <th>Méthode </th>
      <th style="text-align: center;">Since</th>
 
 
       <th>Description</th>
 
       <th>Description</th>
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setAnimating(String objName, boolean animate)</td>
+
       <td>setAnimating(nom, booléen)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Définit si l’objet cité peut être animé. Cela ne lance pas l'animation, utilisez startAnimation() pour le faire.</td>
      <td>Sets whether an object should be animated. This does not start the animation yet, use startAnimation() to do so.</td>
 
 
     </tr>
 
     </tr>
 
       <tr>
 
       <tr>
       <td>void setAnimationSpeed(String objName, double speed)</td>
+
       <td>setAnimationSpeed(nom, nombre)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Définit la vitesse d’animation de l’objet cité.</td>
      <td>Sets the animation speed of an object.</td>
 
 
     </tr>
 
     </tr>
 
   <tr>
 
   <tr>
       <td>void startAnimation()</td>
+
       <td>startAnimation()</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Lance l’animation pour les objets pouvant être animés.</td>
      <td>Starts automatic animation for all objects with the animating flag set, see setAnimating()</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void stopAnimation()</td>
+
       <td>stopAnimation()</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Arrête l’animation en cours.</td>
      <td>Stops animation for all objects with the animating flag set, see setAnimating()</td>
 
 
     </tr>
 
     </tr>
 
   <tr>
 
   <tr>
       <td>boolean isAnimationRunning()</td>
+
       <td>isAnimationRunning()</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Retourne un booléen précisant si une animation est en cours ou non.</td>
      <td>Returns whether automatic animation is currently running.</td>
 
 
     </tr>
 
     </tr>
 
</table>
 
</table>
  
= Getting the state of objects =
+
= Connaître l’état d’un objet =
  
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
 
     <tr>
 
     <tr>
       <th>Method Signature</th>
+
       <th>Méthode</th>
      <th style="text-align: center;">Since</th>
 
 
       <th>Description</th>
 
       <th>Description</th>
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>double getXcoord(String objName)</td>
+
       <td>getXcoord(nom)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne l’abscisse de l’objet cité [ex : getXcoord('A')].
      <td>Returns the cartesian x-coord of the object with the given name.
+
Note : Retourne 0 si l’objet n’est ni un point ni un vecteur.</td>
Note: returns 0 if the object is not a point or a vector.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>double getYcoord(String objName)</td>
+
       <td>getYcoord(nom)</td>
      <td style="text-align: center;">2.7</td>
+
       <td>Retourne l’ordonnée de l’objet cité [ex : getYcoord('u')].  
       <td>Returns the cartesian y-coord of the object with the given name.
+
Note : Retourne 0 si l’objet n’est ni un point ni un vecteur.</td>
Note: returns 0 if the object is not a point or a vector.</td>
 
    </tr>
 
    <tr>
 
      <td>double getValue(String objName)</td>
 
      <td style="text-align: center;">3.2</td>
 
      <td>Returns the double value of the object with the given name (e.g. length of segment, area of polygon). Note: returns 1 for a boolean object with value true. Otherwise 0 is returned.<br>
 
      </td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>String getColor(String objName)</td>
+
       <td>getValue(nom)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne la valeur de l’objet cité ( longueur pour un segment, aire pour un polygone, etc.) [ex : getValue('poly1')].  
      <td>Returns the color of the object with the given name as a hex string, e.g. "#FF0000" for red. Note that the hex string always starts with # and contains no lower case letters.</td>
+
Note : Retourne 0 s’il l’objet n’a pas de valeur associée. Si l’objet est un booléen, retourne 1 pour ‘Vrai’, 0 pour ‘Faux’.     </td>
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td> boolean getVisible(String objName)</td>
+
       <td>getColor(nom)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Retourne la couleur de l’objet cité sous forme d’une chaîne hexadécimale, par ex. : "#FF0000" pour rouge. Note la chaîne hexadécimale commence toujours par # et ne contient pas de lettres minuscules.</td>
      <td>Returns true or false depending on whether the object is visible in the Graphics View. Returns false if the object does not exist.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td> String getValueString(String objName)</td>
+
       <td>getVisible(nom)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne ‘true’ ou ‘false’ suivant que l’objet cité est affiché ou non dans la vue Graphique. Retourne  ‘false’  si l'objet n'existe pas.</td>
      <td>Returns the value of the object with the given name as a string.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>String getDefinitionString(String objName) </td>
+
       <td> getValueString(nom)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne la valeur de l’objet cité sous forme de chaîne.</td>
      <td>Returns the definition of the object with the given name as a string.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>String getCommandString(String objName)</td>
+
       <td>getDefinitionString(nom) </td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne la définition (l’info bulle) de l’objet cité.</td>
      <td>Returns the command of the object with the given name as a string.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>String getObjectType(String objName)</td>
+
       <td>getCommandString(nom)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne la commande à saisir pour créer l’objet cité.</td>
      <td>Returns the type of the given object as a string (like "point", "line", "circle", etc.).</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>boolean exists(String objName)</td>
+
       <td>getObjectType(nom)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne le type de l’objet cité sous forme de chaîne (comme "point", "line", "circle", etc. en Anglais !).</td>
      <td>Returns whether an object with the given name exists in the construction.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>boolean isDefined(String objName)</td>
+
       <td>exists(nom)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Retourne un booléen attestant l’existence ou non de l’objet cité dans la construction.</td>
      <td>Returns whether the given object's value is valid at the moment.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>String [] getAllObjectNames()<br>
+
       <td>isDefined(nom)</td>
      <small style="font-style: italic; font-weight: bold;">Deprecated since 3.0</small> </td>
+
       <td>Retourne un booléen attestant la validité actuelle ou non de l’objet .</td>
       <td style="text-align: center;">2.7</td>
 
      <td>Returns an array with all object names in the construction.
 
Note: using arrays in JavaScript causes problems with some browsers. Use getObjectNumber() and getObjectName() instead.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>int getObjectNumber()</td>
+
       <td>getObjectNumber()</td>
       <td style="text-align: center;">3.0</td>
+
       <td>Retourne le nombre d’objets dans la construction.</td>
      <td>Returns the number of objects in the construction.</td>
 
 
     </tr>
 
     </tr>
 
   <tr>
 
   <tr>
       <td>String getObjectName(int i)</td>
+
       <td>getObjectName(n)</td>
       <td style="text-align: center;">3.0</td>
+
       <td>Retourne le nom du n-ème objet de la construction (attention,  le compteur commence à 0).</td>
      <td>Returns the name of the n-th object of the construction.</td>
 
 
     </tr>
 
     </tr>
 
   <tr>
 
   <tr>
       <td>String getLayer(String objName)</td>
+
       <td>getLayer(nom)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Retourne le numéro du calque de l’objet cité.</td>
      <td>Returns the layer of the object.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>int getLineStyle(String objName)</td>
+
       <td>getLineStyle(nom)</td>
      <td style="text-align: center;">3.2</td>
+
       <td>Retourne le style du trait (de 0 à 4)</td>
       <td>Gets the line style for the object (0 to 4)</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>int getLineThickness(String objName)</td>
+
       <td>getLineThickness(nom)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Retourne l’épaisseur de l’objet (de 1 à 13) (1 par défaut)</td>
      <td>Gets the thickness of the line (1 to 13)</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>int getPointStyle(String objName)</td>
+
       <td>getPointStyle(nom)</td>
      <td style="text-align: center;">3.2</td>
+
       <td>Retourne le style du point (-1 par défaut, 0 disque, 1 cercle, 2 croix,3 plus, 4 diamant plein, 5 diamant vide, 6 triangle (nord), 7 triangle (sud), 8 triangle (est), 9 triangle (ouest))</td>
       <td>Gets the style of points (-1 default, 0 filled circle, 1 circle, 2 cross, 3 plus, 4 filled diamond, 5 unfilled diamond, 6 triangle (north), 7 triangle (south), 8 triangle (east), 9 triangle (west))</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>int getPointSize(String objName)</td>
+
       <td>getPointSize(nom)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Retourne la taille du point (de 1 à 9)</td>
      <td>Gets the size of a point (from 1 to 9)</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>double getFilling(String objName)</td>
+
       <td>getFilling(nom)</td>
       <td style="text-align: center;">3.2</td>
+
       <td>Retourne le remplissage de l’objet (de 0 à 1)</td>
      <td>Gets the filling of an object (from 0 to 1)</td>
 
 
     </tr>
 
     </tr>
 
</table>
 
</table>
  
= Construction / User Interface =
+
= Construction / Interface Utilisateur  =
  
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
 
   <tr>
 
   <tr>
       <th>Method Signature</th>
+
       <th>Méthode</th>
      <th style="text-align: center;">Since</th>
 
 
       <th style="font-weight: bold;">Description</th>
 
       <th style="font-weight: bold;">Description</th>
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setMode(int mode)</td>
+
       <td>setMode(code du mode)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Définit le mode au code fourni
      <td>Sets the mouse mode (i.e. tool) for the graphics window
+
[ex : setMode(0), pour mode Déplacer].
(see [[Reference:Toolbar|toolbar reference]] and the [[Reference:Applet_Parameters|applet parameters]] "showToolBar" and &nbsp;"customToolBar"  )</td>
+
 
 +
(voir [[Reference:Toolbar|toolbar reference]] et [[Reference:Applet_Parameters|applet parameters]] "showToolBar" and &nbsp;"customToolBar"  )</td>
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void openFile(String strURL)</td>
+
       <td>openFile(URL)</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Ouvre le  fichier dont l’URL est donnée sous forme absolue ou relative)[ex : openFile('fichier.ggb')].</td>
      <td>Opens a construction from a&nbsp; file (given as absolute or relative URL string)</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void reset()</td>
+
       <td>reset()</td>
       <td style="text-align: center;">2.7</td>
+
       <td>Réinitialise la construction.<br>
      <td>Reloads the initial construction (given in filename parameter) of this applet.<br>
 
 
       </td>
 
       </td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
       <td>void refreshViews()</td>
+
       <td>refreshViews()</td>
      <td style="text-align: center;">2.7</td>
+
       <td>Rafraîchit l’affichage. Note : cela efface toutes les traces dans la vue Graphique.</td>
       <td>Refreshs all views. Note: this clears all traces in the graphics window.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setOnTheFlyPointCreationActive(boolean flag)<br>
+
       <td>setOnTheFlyPointCreationActive(booléen)<br>
 
       </td>
 
       </td>
      <td style="text-align: center;">3.2</td>
+
       <td>Autorise (true) ou non (false) la création de points "à la volée". Note: A utiliser si vous ne désirez pas que les outils créent des points.</td>
       <td>Turns on the fly creation of points in graphics view on (true) or off (false). Note: this is useful if you don't want tools to have the side effect of creating points. For example, when this flag is set to false, the tool "line through two points" will not create points on the fly when you click on the background of the graphics view.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void hideCursorWhenDragging(boolean flag)<br>
+
       <td>hideCursorWhenDragging(booléen)<br>
 
       </td>
 
       </td>
       <td style="text-align: center;">3.2</td>
+
       <td>Affiche(true) ou non (false) le curseur de la souris quand on déplace un object. </td>
      <td>Hides (true) or shows (false) the mouse cursor (pointer) when dragging an object to change the construction. </td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setRepaintingActive(boolean flag)<br>
+
       <td>setRepaintingActive(booléen)<br>
 
       </td>
 
       </td>
      <td style="text-align: center;">2.7</td>
+
       <td>Active (true) ou non (false) le recalcul de la figure).  
       <td>Turns the repainting of this applet on (true) or off (false).
+
Note : cette méthode est surtout à utiliser quand vous utilisez plusieurs méthodes.</td>
Note: use this method for efficient repainting when you invoke several methods.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setErrorDialogsActive(boolean flag)</td>
+
       <td>setErrorDialogsActive(boolean flag)</td>
       <td style="text-align: center;">3.0</td>
+
       <td>Bascule pour l’affichage ou non du dialogue d’erreur. Note: c'est très utile avec l'utilisation de evalCommand().</td>
      <td>Turns showing of error dialogs on (true) or off (false). Note: this is especially useful together with evalCommand().</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setCoordSystem(double xmin, double xmax, double ymin, double ymax)</td>
+
       <td>setCoordSystem(xmin, xmax,ymin,ymax)</td>
       <td style="text-align: center;">3.0</td>
+
 
      <td>Sets the Cartesian coordinate system of the graphics window.</td>
+
       <td>Définit la fenêtre graphique
 +
[ex : setCoordSystem(-5,10,-1,20)].
 +
</td>
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setAxesVisible(boolean xAxis, boolean yAxis)</td>
+
       <td>setAxesVisible(booléen, booléen)</td>
       <td style="text-align: center;">3.0</td>
+
       <td>Affiche (true) ou Cache (true) indépendamment chacun des axes [ex : setAxesVisible(true, false)].</td>
      <td>Shows or hides the x- and y-axis of the coordinate system in the graphics window.</td>
 
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
       <td>void setGridVisible(boolean flag) </td>
+
       <td>setGridVisible(booléen) </td>
      <td style="text-align: center;">3.0</td>
+
 
       <td>Shows or hides the coordinate grid in the graphics window.</td>
+
       <td>Affiche (true) ou Cache (true) la grille.</td>
 
     </tr>
 
     </tr>
 
</table>
 
</table>
  
=GeoGebraApplet to JavaScript Communication=
+
=Communication de GeoGebraApplet à JavaScript=
 +
Avec ces méthodes vous pouvez implémenter une communication de l’appliquette au JavaScript. Quand vous utilisez une des méthodes suivantes, vous devez vous assurer que vous avez inséré l’option <span class="term"><span class="highlightedSearchTerm"><span style="font-weight: bold;">MAYSCRIPT</span> à la fin de la ligne d’appel de l’appliquette.
  
With these methods you can implement Applet to JavaScript communication. When you use any of the following methods, you should make sure to insert the <span class="term"><span class="highlightedSearchTerm"><span style="font-weight: bold;">MAYSCRIPT</span> option add the end of the first line of your applet tag. For example:
+
Par exemple :
  
 
<span style="font-family: monospace;">&lt;applet name="ggbApplet" code="geogebra.GeoGebraApplet" codebase="." archive="geogebra.jar" width="500" height="250" </span><span style="font-weight: bold; font-family: monospace; color: rgb(255, 0, 0);">MAYSCRIPT</span><span style="font-family: monospace;">&gt;</span>.
 
<span style="font-family: monospace;">&lt;applet name="ggbApplet" code="geogebra.GeoGebraApplet" codebase="." archive="geogebra.jar" width="500" height="250" </span><span style="font-weight: bold; font-family: monospace; color: rgb(255, 0, 0);">MAYSCRIPT</span><span style="font-family: monospace;">&gt;</span>.
The <span class="highlightedSearchTerm">MAYSCRIPT</span> option <span class="highlightedSearchTerm">is</span> only needed for GeoGebraApplet to JavaScript communication; it <span class="highlightedSearchTerm">is</span> not needed for JavaScript to access the GeoGebraApplet methods.  
+
L'option <span class="highlightedSearchTerm">MAYSCRIPT n'est</span> seulement nécessaire que pour la communication de GeoGebraAppletavec JavaScript ; elle<span class="highlightedSearchTerm">n'est</span> pas nécessaire à JavaScript pour accéder au méhtodes de GeoGebraApplet.  
For example, these methods can be used to:
+
Par exemple, ces méthodes peuvent être utilisées pour :
 
* monitor user actions (see [http://www.geogebra.org/source/program/applet/geogebra_applet_java2javascript.htm java2javascript example])
 
* monitor user actions (see [http://www.geogebra.org/source/program/applet/geogebra_applet_java2javascript.htm java2javascript example])
 
* communicate between two GeoGebra applets (see [http://www.geogebra.org/source/program/applet/geogebra_applet_java2java.htm java2java example])
 
* communicate between two GeoGebra applets (see [http://www.geogebra.org/source/program/applet/geogebra_applet_java2java.htm java2java example])

Version du 10 décembre 2011 à 23:09

EN TRAVAUX !!! --Noel Lambert 10 décembre 2011 à 19:35 (CET)


Description des méthodes publiques utilisables dans geogebra.GeoGebraApplet à l’aide de JavaScript par l’intermédiaire d’une page HTML.


Exemples

Exemple 1 : le fragment de code HTML suivant ajoute un bouton "Réinitialiser" dans une page HTML, ce qui permet à l’utilisateur de ramener la construction affichée par GeoGebra dans son état initial : <form> <input type="button" value="Réinitialiser" onclick="document.applets[0].reset();"> </form>


Exemple 2 : celui-ci ajoute deux boutons "Cacher A" et " Afficher A" pour changer l’état d’affichage de l’objet nommé “A" dans la construction <form> <input type="button" value="Cacher A" onclick="document.applets[0].setVisible('A', false);"> <input type="button" value="Afficher A" onclick="document.applets[0].setVisible('A', true);"> </form>


Exemple 3: Une fonction JavaScript "maConstruction()" est utilisée pour appeler plusieurs méthodes de l’appliquette GeoGebra. Note : La langue est fixée à Français ("fr") avec le paramètre "language" dans la balise de l’appliquette afin de faire en sorte que la commande française "Droite" fonctionne. <applet name="ggbApplet" code="geogebra.GeoGebraApplet"

       archive="geogebra.jar" 
       width=200 height=40>
   <param name ="fileNom" value="circle.ggb">
   <param name ="framePossible" value="false">
   <param name ="language" value="fr">
    <a href="http://www.java.com"> Installez  Java 1.4.2</a> (ou supérieure) pour utiliser cette  page.

</applet> <script type="text/javascript"> function maConstruction() { var applet = document.ggbApplet; applet.evalCommand("A = (1,1)"); applet.evalCommand("B = (3,2)"); applet.evalCommand("s = Droite[A, B]"); } </script> <form> <input type="button" value="Faire la construction" onclick="maConstruction();"> </form>


Exemple 4: Have a look at the source code of the following example worksheet that uses JavaScript.

 http://www.geogebra.org/source/program/applet/geogebra_applet_javascript_test.htm

Exemple 5: This is an example worksheet that uses an add listener to check when a particular construction has been completed (and then says "Well done").

 http://www.geogebra.org/en/examples/javascriptAutomaticCheckingExercise.html

Méthodes utilisables

Méthode Description
evalCommand(commande) Évalue la chaîne comme si vous l’aviez entrée dans le champ de saisie [ex : evalCommand('s = Droite[A, B]')].
Vous pouvez utiliser plusieurs commandes en les séparant par "\n"
Note : Utilisez le paramètre “language” language parameter pour vous assurez que la commande de votre langue est reconnue.
void setUndoPoint() Sets an undo point. Useful if you want the user to be able to undo that action of evalCommand eg if you have made an HTML button to act as a custom tool

With these methods you can implement Applet to JavaScript communication. When you use any of the following methods, you should make sure to insert the MAYSCRIPT option add the end of the first line of your applet tag. For example:

 <applet name="ggbApplet" code="geogebra.GeoGebraApplet" codebase="." archive="geogebra.jar" width="500" height="250" MAYSCRIPT>

The MAYSCRIPT option is only needed for GeoGebraApplet to JavaScript communication; it is not needed for JavaScript to access the GeoGebraApplet methods.

For example, these methods can be used to

Définir l’état d’un objet

General methods

Méthode Description
deleteObject(nom) Efface l’objet cité.[ex : deleteObject('A')].
setValue(nom, valeur) Affecte la valeur à l’objet cité [ex : setValue('n',36)]. Note : Si cet objet n’est pas un nombre, rien ne se passe. Si l’objet est un booléen, utiliser la valeur 1 pour le mettre à ‘Vrai’, n’importe quelle valeur pour le mettre à ‘Faux’.
setCoords(nom, x, y) Affecte les coordonnées à l’objet [ex : setCoords('A',-1,3)]. Note : Si cet objet n’est ni point ni vecteur, rien ne se passe.
setColor(nom, rouge, vert, bleu) Affecte la couleur RVB à l’objet [ setColor('A',200,100,100)].
setVisible(nom, booléen) Affiche (true) ou Cache (false) l’objet cité dans la vue Graphique [ex : setVisible('A',true)].
setLabelVisible(nom, booléen) Affiche (true) ou Cache (false) l’étiquette de l’objet cité dans la vue Graphique [ex : setLabelVisible('A',false)].
setLabelStyle(nom, booléen) Définit le style de l’étiquette de l’objet cité dans Graphique. Nom = 0, Nom & Valeur = 1, Valeur = 2 et Légende=3. [ex : setLabelStyle('A',1)],
setFixed(nom, booléen) Définit la liberté de l’objet cité [ex : setFixed('A',true)].
Note : Les objets fixes ne peuvent être modifiés.
setTrace(nom, booléen) Active ou non la trace de l’objet cité [ex : setTrace('A',false)].
renameObject(ancien nom, nouveau nom) 3.2 Renomme l’objet ancien nom en l’objet nouveau nom
setLayer(nom) Définit le calque de l’objet cité.
setLayerVisible(n°, booléen) Affiche ou cache tous les objets du calque n°
setLineStyle(nom,entier) Définit le style du trait (de 0 à 4)
setLineThickness(nom,entier) Définit l’épaisseur de l’objet (de 1 à 13) (1 par défaut)
setPointStyle(nom,entier) Définit le style du point (-1 par défaut, 0 disque, 1 cercle, 2 croix,3 plus, 4 diamant plein, 5 diamant vide, 6 triangle (nord), 7 triangle (sud), 8 triangle (est), 9 triangle (ouest))
setPointSize(nom,entier) Définit la taille du point (de 1 à 9)
setFilling(nom,nombre) Définit le remplissage de l’objet (de 0 à 1)

Animation automatique

Méthode Description
setAnimating(nom, booléen) Définit si l’objet cité peut être animé. Cela ne lance pas l'animation, utilisez startAnimation() pour le faire.
setAnimationSpeed(nom, nombre) Définit la vitesse d’animation de l’objet cité.
startAnimation() Lance l’animation pour les objets pouvant être animés.
stopAnimation() Arrête l’animation en cours.
isAnimationRunning() Retourne un booléen précisant si une animation est en cours ou non.

Connaître l’état d’un objet

Méthode Description
getXcoord(nom) Retourne l’abscisse de l’objet cité [ex : getXcoord('A')]. Note : Retourne 0 si l’objet n’est ni un point ni un vecteur.
getYcoord(nom) Retourne l’ordonnée de l’objet cité [ex : getYcoord('u')]. Note : Retourne 0 si l’objet n’est ni un point ni un vecteur.
getValue(nom) Retourne la valeur de l’objet cité ( longueur pour un segment, aire pour un polygone, etc.) [ex : getValue('poly1')]. Note : Retourne 0 s’il l’objet n’a pas de valeur associée. Si l’objet est un booléen, retourne 1 pour ‘Vrai’, 0 pour ‘Faux’.
getColor(nom) Retourne la couleur de l’objet cité sous forme d’une chaîne hexadécimale, par ex. : "#FF0000" pour rouge. Note la chaîne hexadécimale commence toujours par # et ne contient pas de lettres minuscules.
getVisible(nom) Retourne ‘true’ ou ‘false’ suivant que l’objet cité est affiché ou non dans la vue Graphique. Retourne ‘false’ si l'objet n'existe pas.
getValueString(nom) Retourne la valeur de l’objet cité sous forme de chaîne.
getDefinitionString(nom) Retourne la définition (l’info bulle) de l’objet cité.
getCommandString(nom) Retourne la commande à saisir pour créer l’objet cité.
getObjectType(nom) Retourne le type de l’objet cité sous forme de chaîne (comme "point", "line", "circle", etc. en Anglais !).
exists(nom) Retourne un booléen attestant l’existence ou non de l’objet cité dans la construction.
isDefined(nom) Retourne un booléen attestant la validité actuelle ou non de l’objet .
getObjectNumber() Retourne le nombre d’objets dans la construction.
getObjectName(n) Retourne le nom du n-ème objet de la construction (attention, le compteur commence à 0).
getLayer(nom) Retourne le numéro du calque de l’objet cité.
getLineStyle(nom) Retourne le style du trait (de 0 à 4)
getLineThickness(nom) Retourne l’épaisseur de l’objet (de 1 à 13) (1 par défaut)
getPointStyle(nom) Retourne le style du point (-1 par défaut, 0 disque, 1 cercle, 2 croix,3 plus, 4 diamant plein, 5 diamant vide, 6 triangle (nord), 7 triangle (sud), 8 triangle (est), 9 triangle (ouest))
getPointSize(nom) Retourne la taille du point (de 1 à 9)
getFilling(nom) Retourne le remplissage de l’objet (de 0 à 1)

Construction / Interface Utilisateur

Méthode Description
setMode(code du mode) Définit le mode au code fourni

[ex : setMode(0), pour mode Déplacer].

(voir toolbar reference et applet parameters "showToolBar" and  "customToolBar" )
openFile(URL) Ouvre le fichier dont l’URL est donnée sous forme absolue ou relative)[ex : openFile('fichier.ggb')].
reset() Réinitialise la construction.
refreshViews() Rafraîchit l’affichage. Note : cela efface toutes les traces dans la vue Graphique.
setOnTheFlyPointCreationActive(booléen)
Autorise (true) ou non (false) la création de points "à la volée". Note: A utiliser si vous ne désirez pas que les outils créent des points.
hideCursorWhenDragging(booléen)
Affiche(true) ou non (false) le curseur de la souris quand on déplace un object.
setRepaintingActive(booléen)
Active (true) ou non (false) le recalcul de la figure). Note : cette méthode est surtout à utiliser quand vous utilisez plusieurs méthodes.
setErrorDialogsActive(boolean flag) Bascule pour l’affichage ou non du dialogue d’erreur. Note: c'est très utile avec l'utilisation de evalCommand().
setCoordSystem(xmin, xmax,ymin,ymax) Définit la fenêtre graphique

[ex : setCoordSystem(-5,10,-1,20)].

setAxesVisible(booléen, booléen) Affiche (true) ou Cache (true) indépendamment chacun des axes [ex : setAxesVisible(true, false)].
setGridVisible(booléen) Affiche (true) ou Cache (true) la grille.

Communication de GeoGebraApplet à JavaScript

Avec ces méthodes vous pouvez implémenter une communication de l’appliquette au JavaScript. Quand vous utilisez une des méthodes suivantes, vous devez vous assurer que vous avez inséré l’option MAYSCRIPT à la fin de la ligne d’appel de l’appliquette.

Par exemple :

<applet name="ggbApplet" code="geogebra.GeoGebraApplet" codebase="." archive="geogebra.jar" width="500" height="250" MAYSCRIPT>. L'option MAYSCRIPT n'est seulement nécessaire que pour la communication de GeoGebraAppletavec JavaScript ; ellen'est pas nécessaire à JavaScript pour accéder au méhtodes de GeoGebraApplet. Par exemple, ces méthodes peuvent être utilisées pour :

Method Signature Since Description
void registerAddListener(String JSFunctionName) 3.0 Registers a JavaScript function as an add listener for the applet's construction. Whenever a new object is created in the GeoGebraApplet's construction, the JavaScript function JSFunctionName is called using the name of the newly created object as its single argument.

Example: First, register a listening JavaScript function:

ggbApplet.registerAddListener("myAddListenerFunction");

When an object "A" is created, the GeoGebra Applet will call the Javascript function

myAddListenerFunction("A");
void unregisterAddListener(String objName) 3.0 Removes a previously registered add listener, see registerAddListener()
void registerRemoveListener(String JSFunctionName) 3.0 Registers a JavaScript function as a remove listener for the applet's construction. Whenever an object is deleted from the GeoGebraApplet's construction, the JavaScript function JSFunctionName is called using the name of the deleted object as its single argument. Note: when a construction is cleared, remove is not called for every single object, see registerClearListener().

Example: First, register a listening JavaScript function:

ggbApplet.registerRemoveListener("myRemoveListenerFunction");

When the object "A" is deleted, the GeoGebra Applet will call the Javascript function

myRemoveListenerFunction("A");
void unregisterRemoveListener(String objName) 3.0 Removes a previously registered remove listener, see registerRemoveListener()
void registerUpdateListener(String JSFunctionName) 3.0 Registers a JavaScript function as a update listener for the applet's construction. Whenever any object is updated in the GeoGebraApplet's construction, the JavaScript function JSFunctionNameis called using the name of the updated object as its single argument. Note: when you only want to listen for the updates of a single object use registerObjectUpdateListener() instead.

Example: First, register a listening JavaScript function:

ggbApplet.registerUpdateListener("myUpdateListenerFunction");

When the object "A" is updated, the GeoGebra Applet will call the Javascript function

myUpdateListenerFunction("A");
void unregisterUpdateListener(String objName) 3.0 Removes a previously registered update listener, see registerUpdateListener()
void registerObjectUpdateListener(String objName, String JSFunctionName) 3.0 Registers a JavaScript function as an update listener for a single object. Whenever the object with the given name is updated, the JavaScript function JSFunctionNameis called using the name of the updated object as its single argument. If objName previously had a mapping JavaScript function, the old value is replaced. Note: all object updated listeners are unregistered when their object is removed or the construction is cleared, see registerRemoveListener() and registerClearListener().

Example: First, register a listening JavaScript function:

ggbApplet.registerObjectUpdateListener("A", "myAupdateListenerFunction");

Whenever the object A is updated, the GeoGebra Applet will call the Javascript function

myAupdateListenerFunction("A");

Note: an object update listener will still work after an object is renamed.

void unregisterObjectUpdateListener(String objName) 3.0 Removes a previously registered object update listener of the object with the given name, see registerObjectUpdateListener()
void registerRenameListener(String JSFunctionName) 3.0 Registers a JavaScript function as a rename listener for the applet's construction. Whenever an object is renamed in the GeoGebraApplet's construction, the JavaScript function JSFunctionName is called using the old name and the new name of the renamed object as its two arguments.

Example: First, register a listening JavaScript function:

ggbApplet.registerRenameListener("myRenameListenerFunction");

When an object "A" is renamed to "B", the GeoGebra Applet will call the Javascript function

myRenameListenerFunction("A", "B");
void unregisterRenameListener(String objName) 3.0 Removes a previously registered rename listener, see registerRenameListener()
void registerClearListener(String JSFunctionName) 3.0 Registers a JavaScript function as a clear listener for the applet's construction. Whenever the construction in the GeoGebraApplet is cleared (i.e. all objects are removed), the JavaScript function JSFunctionName is called using no arguments. Note: all update listeners are unregistered when a construction is cleared. See registerUpdateListener() and registerRemoveListener().

Example: First, register a listening JavaScript function:

ggbApplet.registerClearListener("myClearListenerFunction");

When the construction is cleared (i.e. after reseting a construction or opening a new construction file), the GeoGebra Applet will call the Javascript function

myClearListenerFunction();
void unregisterClearListener(String JSFunctionName) 3.0 Removes a previously registered clear listener, see registerClearListener()

GeoGebra's XML format

With these methods you can set everything in a construction (see XML Reference ).

Method Signature Since Description
void evalXML(String xmlString) 2.7 Evaluates the given XML string and changes the current construction. Note: the construction is NOT cleared before evaluating the XML string.
void setXML(String xmlString) 2.7 Evaluates the given XML string and changes the current construction. Note: the construction is cleared before evaluating the XML string. This method could be used to load constructions.
String getXML()
2.7 Returns the current construction in GeoGebra's XML format. This method could be used to save constructions.
String getXML(String objName)
3.2 Returns the GeoGebra XML string for the given object, i.e. only the <element> tag is returned.
String getAlgorithmXML(String objName)
3.2 For a dependent GeoElement objName the XML string of the parent algorithm and all its output objects is returned. For a free GeoElement objName "" is returned.

Miscellaneous

Method Signature Since Description
String evalMathPiper(String string) 3.2 Passes the string to MathPiper and returns the result as a String.
String getIPAddress() 3.2 Returns the IP address of the local computer as a String eg "192.168.0.4"
String getHostname() 3.2 Returns the hostname of the local computer as a String
void debug(String string) 3.2 Prints the string to the Java Console
© 2024 International GeoGebra Institute