“Comments:參考:JavaScript”的版本间的差异

来自GeoGebra Manual
跳转至: 导航搜索
 
(未显示同一用户的20个中间版本)
第1行: 第1行:
GeoGebra 4, October 2011
+
= GGB 檔中使用 JavaScript =
 +
[[File:OnClick.png|frame|物件的 OnClick 事件]]
 +
如果在物件的「程式」頁面中要使用 JavaScript 來控制 GGB 的話,可以使用 {{Key|ggbApplet|blue}} 這個關鍵字,然後用下面介紹的各種 JavaScript 指令。
  
Markus Hohenwarter, Michael Borcherds
+
{{Example|1=如果我們在一個物件的 OnClick 事件中輸入以下的程式碼,則當此物件被滑鼠按到時,會自動產生一個數列。}}
  
This document describes public methods available in geogebra.GeoGebraApplet to be used from an HTML page via JavaScript.
+
var a = ggbApplet;
 +
a.evalCommand('n = 3');
 +
a.evalCommand('s = Sequence[k^2, k, 1, n]');
  
= Examples =
+
{{Note|1= 在 GeoGebra 內部使用 JavaScript 宣告 ggbApplet 的時候,要使用:}}
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:
+
var a = {{Key|ggbApplet|blue}};
 +
不能使用:
 +
var a = {{Key|document|red}}.ggbApplet;
 +
否則會產生「document 物件不存在」的錯誤!
  
  <form>
+
= 網頁中使用 JavaScript =
   <input type="button" value="Reset" onclick="document.applets[0].reset();">
+
{{Example|1=下面的 HTML 網頁碼會在網頁中產生一個「按鈕」,按下此鈕時,繪圖區會回到初始狀態。}}
  </form>
+
<input type="button" value=" 重設" onclick="{{Key|document.applets[0].reset();|blue}}">
  
Example 2: this adds two buttons "Hide A" and "Show A" change the visibility state of an object named "A" in the construction
+
{{Example|1=下面的 HTML 網頁碼會產生兩個「按鈕」,第一個可以隱藏 A 點,第二個可以顯示 A 點。}}
 +
<input type="button" value="隱藏 A 點" onclick="document.applets[0].{{Key|setVisible('A', false)|blue}};">
 +
<input type="button" value=" 顯示 A " onclick="document.applets[0].{{Key|setVisible('A', true)|blue}};">
  
  <form>
+
{{Example|1=下面的 HTML 網頁碼會產生一個「按鈕」,按下此鈕時,會畫出 AB 兩點,與通過此兩點的直線。}}
   <input type="button" value="Hide A" onclick="document.applets[0].setVisible('A', false);">
+
<applet name="ggbApplet" ... > </applet>
   <input type="button" value="Show A" onclick="document.applets[0].setVisible('A', true);">
+
......
  </form>
+
<script type="text/javascript">
 +
{{Key|1=function drawLineAB() {
 +
var applet = document.ggbApplet;
 +
applet.evalCommand("A = (1,1)");
 +
applet.evalCommand("B = (3,2)");
 +
applet.evalCommand("s = Line[A, B]");
 +
} |2=blue}}
 +
</script>
 +
......
 +
<input type="button" value="Do construction" onclick="{{Key|drawLineAB()|blue}};">
  
Example 3: a JavaScript function "myLittleConstruction()" is used to call several methods of the GeoGebraApplet
+
{{Hint|請打開下面網頁的原始碼,你就可以看到如過透過 JavaScript 來控制 GGB 的實際例子。}}
 +
* http://www.geogebra.org/source/program/applet/geogebra_applet_javascript_test.htm
  
  <applet name="ggbApplet" code="geogebra.GeoGebraApplet"
+
{{Hint|下面的網頁用來示範「事件處理」的概念。當我們利用作圖工具產生新物件時,網頁中所設定的「新增物件處理器」會檢查你的作圖是否已經完成,然後給你適當的回應。}}
   archive="geogebra.jar"
+
* http://www.geogebra.org/en/examples/javascriptAutomaticCheckingExercise.html
   codebase="http://jars.geogebra.org/webstart/4.0/unsigned/"
 
   width=200 height=40>
 
  This is a Java Applet created using GeoGebra from www.geogebra.org - it looks like you don't have Java installed, please go to www.java.com
 
  </applet>
 
  <script type="text/javascript">
 
   function myLittelConstruction() {
 
    var applet = document.ggbApplet;
 
    applet.evalCommand("A = (1,1)");
 
    applet.evalCommand("B = (3,2)");
 
    applet.evalCommand("s = Line[A, B]");
 
   }
 
  </script>
 
  <form>
 
   <input type="button" value="Do construction" onclick="myLittleConstruction();">
 
  </form>
 
  
Example 4: Have a look at the source code of the following example worksheet that uses JavaScript.
+
{{Hint|下面是一個利用 JavaScript 產生互動效果的例子。網頁開啟後,會隨機畫一條直線,你必須填入正確的「斜率」,如果回答正確,它會再隨機畫另一條直線讓你回答它的斜率。}}
  http://www.geogebra.org/source/program/applet/geogebra_applet_javascript_test.htm
+
* http://www.geogebra.org/web/milestones/SlopeTestWeb.html
  
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").
+
= 通用指令 =
  http://www.geogebra.org/en/examples/javascriptAutomaticCheckingExercise.html
+
{{Script|evalCommand|命令字串|若執行成功則傳回 {{Key|true}},若失敗則傳回 {{Key|false}}。|appApplet.{{Key|evalCommand|red}}('SetValue[n, 3]');|此指令會執行「命令字串」中所指定的 GGB 指令,此與直接在「命令列」中下該指令有相同的效果。從 3.2 版起,我們可以在「命令字串」中加入特殊的換行字串「{{Key|\n|blue}}」,這樣一來,我們就可以同時下許多個指令。}}
 +
{{Script|setUndoPoint| |無。|appApplet.{{Key|setUndoPoint|red}}();|5=此指令可用於設定由 <code>evalCommand()</code> 所產生的動作的回復點。}}
  
Example 6: This example shows how to interface JavaScript with GeoGebraWeb
+
= 設定物件屬性=
  http://www.geogebra.org/web/milestones/SlopeTestWeb.html
 
 
 
= Available Methods =
 
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
   <tr>
+
<tr>
    <th>Method Signature</th>
+
<th>函數</th>
    <th style="text-align: center;">Since</th>
+
<th style="text-align: center;">版本</th>
    <th>Description</th>
+
<th>說明</th>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>boolean evalCommand(String cmdString)</td>
+
<td> void deleteObject(String objName)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">2.7</td>
    <td> Evaluates the given string just like it would be evaluated when entered into GeoGebra's input bar. Returns whether command evaluation was successful. <br> From GeoGebra 3.2 you can pass multiple commands at once by separating them with \n. <br> Note: you must use English commands names to ensure that it will work with all versions of GeoGebra<br>
+
<td>Deletes the object with the given name.</td>
    </td>
+
</tr>
   </tr>
+
<tr>
   <tr>
+
<td>void setValue(String objName, double value)</td>
    <td>void setUndoPoint()</td>
+
<td style="text-align: center;">3.2</td>
    <td style="text-align: center;">3.2</td>
+
<td>Sets the double value of the object with the given name. Note: if the specified object is boolean, use a value of 1 to set it to true and any other value to set it to false. For any other object type, nothing is done.</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>
+
</tr>
    </td>  
+
<tr>
    </tr>
+
<td>void setCoords(String objName, double x, double y)</td>
</table>
+
<td style="text-align: center;">3.0</td>
 
+
<td>Sets the coordinates of the object with the given name.
 
 
= Setting the state of objects =
 
 
 
==設定物件屬性==
 
<table style="width: 100%;" class="pretty">
 
   <tr>
 
    <th>函數</th>
 
    <th style="text-align: center;">版本</th>
 
    <th>說明</th>
 
   </tr>
 
   <tr>
 
    <td> void deleteObject(String objName)</td>
 
    <td style="text-align: center;">2.7</td>
 
    <td>Deletes the object with the given name.</td>
 
   </tr>
 
   <tr>
 
    <td>void setValue(String objName, double value)</td>
 
    <td style="text-align: center;">3.2</td>
 
    <td>Sets the double value of the object with the given name. Note: if the specified object is boolean, use a value of 1 to set it to true and any other value to set it to false. For any other object type, nothing is done.</td>
 
   </tr>
 
   <tr>
 
    <td>void setCoords(String objName, double x, double y)</td>
 
    <td style="text-align: center;">3.0</td>
 
    <td>Sets the coordinates of the object with the given name.
 
 
Note: if the specified object is not a point or a vector, nothing is done.</td>
 
Note: if the specified object is not a point or a vector, nothing is done.</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void {{Key|setColor|blue}}(物件名, 紅, 綠, 藍)</td>
+
<td>void {{Key|setColor|blue}}(物件名, 紅, 綠, 藍)</td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">2.7</td>
    <td>設定物件的顏色,紅綠藍 (RGB) 的顏色值為 {{Key|0 ~ 255}}。<br />例如:<code>document.ggbApplet.{{Key|setColor|blue}}("lineAB", 255, 0, 0)</code></td>
+
<td>設定物件的顏色,紅綠藍 (RGB) 的顏色值為 {{Key|0 ~ 255}}。<br />例如:<code>document.ggbApplet.{{Key|setColor|blue}}("lineAB", 255, 0, 0)</code></td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setVisible(String objName, boolean visible) </td>
+
<td>void setVisible(String objName, boolean visible) </td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">2.7</td>
    <td>Shows or hides the object with the given name in the graphics window.</td>
+
<td>Shows or hides the object with the given name in the graphics window.</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setLabelVisible(String objName, boolean visible) </td>
+
<td>void setLabelVisible(String objName, boolean visible) </td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Shows or hides the label of the object with the given name in the graphics window.</td>
+
<td>Shows or hides the label of the object with the given name in the graphics window.</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setLabelStyle(String objName, int style)</td>
+
<td>void setLabelStyle(String objName, int style)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Sets the label style of the object with the given name in the graphics window. Possible label styles are NAME = 0, NAME_VALUE = 1, VALUE = 2 and (from GeoGebra 3.2) CAPTION = 3</td>
+
<td>Sets the label style of the object with the given name in the graphics window. Possible label styles are NAME = 0, NAME_VALUE = 1, VALUE = 2 and (from GeoGebra 3.2) CAPTION = 3</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setFixed(String objName, boolean flag)</td>
+
<td>void setFixed(String objName, boolean flag)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Sets the fixed state of the object with the given name. Note: fixed objects cannot be changed.</td>
+
<td>Sets the fixed state of the object with the given name. Note: fixed objects cannot be changed.</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setTrace(String objName, boolean flag)</td>
+
<td>void setTrace(String objName, boolean flag)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Turns the trace of the object with the given name on or off.</td>
+
<td>Turns the trace of the object with the given name on or off.</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>boolean renameObject(String oldObjName, String newObjName)</td>
+
<td>boolean renameObject(String oldObjName, String newObjName)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Renames oldObjName to newObjName. Returns whether the rename was successful</td>
+
<td>Renames oldObjName to newObjName. Returns whether the rename was successful</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setLayer(String objName, int layer)</td>
+
<td>void setLayer(String objName, int layer)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Sets the layer of the object</td>
+
<td>Sets the layer of the object</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setLayerVisible(int layer, boolean visible)</td>
+
<td>void setLayerVisible(int layer, boolean visible)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Shows or hides the all objects in the given layer</td>
+
<td>Shows or hides the all objects in the given layer</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setLineStyle(String objName, int style)</td>
+
<td>void {{Key|setLineStyle|blue}}( 物件名, 樣式編號)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Sets the line style for the object (0 to 4)</td>
+
<td> 設定線條樣式:0 - 實線,1 - 長虛線,2 - 短虛線,3 - 點虛線,4 - 長點虛線。</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void {{Key|setLineThickness|blue}}(物件名, 厚度)</td>
+
<td>void {{Key|setLineThickness|blue}}(物件名, 厚度)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>設定物件(線、圓等)的厚度,值從 {{Key|1 ~ 13}}。</td>
+
<td>設定物件(線、圓等)的厚度,值從 {{Key|1 ~ 13}}。</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setPointStyle(String objName, int style)</td>
+
<td>void setPointStyle(String objName, int style)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</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>
+
<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>void setPointSize(String objName, int size)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Sets the size of a point (from 1 to 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>void setFilling(String objName, double filling)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Sets the filling of an object (from 0 to 1)</td>
+
<td>Sets the filling of an object (from 0 to 1)</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>String getPNGBase64(double exportScale, boolean transparent, double DPI)</td>
+
<td>String getPNGBase64(double exportScale, boolean transparent, double DPI)</td>
    <td style="text-align: center;">4.0</td>
+
<td style="text-align: center;">4.0</td>
    <td>Returns Graphics View 1 as a base64-encoded String<br>eg var str = ggbApplet.getPNGBase64(1, true, 72);    </td>
+
<td>Returns Graphics View 1 as a base64-encoded String<br>eg var str = ggbApplet.getPNGBase64(1, true, 72);    </td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>boolean writePNGtoFile(String filename, double exportScale, boolean transparent, double DPI)
+
<td>boolean writePNGtoFile(String filename, double exportScale, boolean transparent, double DPI)
 
</td>
 
</td>
    <td style="text-align: center;">4.0</td>
+
<td style="text-align: center;">4.0</td>
    <td>Exports Graphics View 1 to a .PNG file '''(signed applets only)''' <br>
+
<td>Exports Graphics View 1 to a .PNG file '''(signed applets only)''' <br>
 
eg var success = ggbApplet.writePNGtoFile("c:\\test.png", 1, false, 300);    </td>
 
eg var success = ggbApplet.writePNGtoFile("c:\\test.png", 1, false, 300);    </td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>boolean isIndependent(String objName)
+
<td>boolean isIndependent(String objName)
 
</td>
 
</td>
    <td style="text-align: center;">4.0</td>
+
<td style="text-align: center;">4.0</td>
    <td> checks if '''objName''' is independent    </td>
+
<td> checks if '''objName''' is independent    </td>
   </tr>
+
</tr>
  <tr>
+
<tr>
    <td>boolean isMoveable(String objName)
+
<td>boolean isMoveable(String objName)
 
</td>
 
</td>
    <td style="text-align: center;">4.0</td>
+
<td style="text-align: center;">4.0</td>
    <td> checks if '''objName''' is is moveable</td>
+
<td> checks if '''objName''' is is moveable</td>
   </tr>
+
</tr>
  <tr>
+
<tr>
    <td>String getBase64()
+
<td>String getBase64()
 
</td>
 
</td>
    <td style="text-align: center;">4.0</td>
+
<td style="text-align: center;">4.0</td>
    <td> Gets the current construction as a base64-encoded .ggb file</td>
+
<td> Gets the current construction as a base64-encoded .ggb file</td>
   </tr>
+
</tr>
    <td>void setBase64(String)
+
<td>void setBase64(String)
 
</td>
 
</td>
    <td style="text-align: center;">4.0</td>
+
<td style="text-align: center;">4.0</td>
    <td> Sets the current construction from a base64-encoded .ggb file</td>
+
<td> Sets the current construction from a base64-encoded .ggb file</td>
 
</table>
 
</table>
  
==Automatic Animation==
+
= 設定動態效果=
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
   <tr>
+
<tr>
    <th>Method Signature</th>
+
<th> 函數</th>
    <th style="text-align: center;">Since</th>
+
<th style="text-align: center;"> 版本</th>
    <th>Description</th>
+
<th> 說明</th>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setAnimating(String objName, boolean animate)</td>
+
<td>{{Key|setAnimating|blue}}</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Sets whether an object should be animated. This does not start the animation yet, use startAnimation() to do so.</td>
+
<td> 格式:setAnimating( 物件名, 啟動動畫? )<br>{{note|設定物件要不要啟動動畫效果。}}{{Example|1=<code>setAnimating("A", {{Key|true|red}})</code>}}{{Warning|光使用此函數並不能使物件產生動畫效果,必須搭配 {{Key|startAnimation}}() 才行!}}</td>
   </tr>
+
</tr>
    <tr>
+
<tr>
    <td>void setAnimationSpeed(String objName, double speed)</td>
+
<td>{{Key|setAnimationSpeed|blue}}</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Sets the animation speed of an object.</td>
+
<td> 格式:setAnimationSpeed(物件名, 速度){{note|設定物件的動畫速度。}}</td>
   </tr>
+
</tr>
  <tr>
+
<tr>
    <td>void startAnimation()</td>
+
<td>{{Key|startAnimation}}</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Starts automatic animation for all objects with the animating flag set, see setAnimating()</td>
+
<td> 格式:startAnimation(){{note|正式啟動動畫功能。注意:只有用過 setAnimating() 設定過的物件才會動喔!}}</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void stopAnimation()</td>
+
<td>void stopAnimation()</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Stops animation for all objects with the animating flag set, see setAnimating()</td>
+
<td>Stops animation for all objects with the animating flag set, see setAnimating()</td>
   </tr>
+
</tr>
  <tr>
+
<tr>
    <td>boolean isAnimationRunning()</td>
+
<td>boolean isAnimationRunning()</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Returns whether automatic animation is currently running.</td>
+
<td>Returns whether automatic animation is currently running.</td>
   </tr>
+
</tr>
 
</table>
 
</table>
  
= Getting the state of objects =
+
= 取得物件屬性 =
 +
{{Script|getXcoord|物件名稱|物件的 x 座標。若物件不是點或向量,則傳回 0。|ggbApplet.{{Key|getXcoord|red}}('A')|}}
 +
{{Script|getYcoord|物件名稱|物件的 y 座標。若物件不是點或向量,則傳回 0。|ggbApplet.{{Key|getYcoord|red}}('A')|}}
 +
{{Script|getValue|物件名稱|物件的數值、長度、面積等。若物件為「[[真假值]]」,則 {{Key|true}} 傳回 1,{{Key|false}} 傳回 0。|ggbApplet.{{Key|getValue|red}}('areaABC')|}}
  
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
   <tr>
+
<tr>
    <th>Method Signature</th>
+
<th>Method Signature</th>
    <th style="text-align: center;">Since</th>
+
<th style="text-align: center;">Since</th>
    <th>Description</th>
+
<th>Description</th>
   </tr>
+
</tr>
   <tr>
+
 
    <td>double getXcoord(String objName)</td>
+
<tr>
    <td style="text-align: center;">2.7</td>
+
<td>String getColor(String objName)</td>
    <td>Returns the cartesian x-coord of the object with the given name.
+
<td style="text-align: center;">2.7</td>
Note: returns 0 if the object is not a point or a vector.</td>
+
<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>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>double getYcoord(String objName)</td>
+
<td> boolean getVisible(String objName)</td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">3.2</td>
    <td>Returns the cartesian y-coord of the object with the given name.
+
<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>
Note: returns 0 if the object is not a point or a vector.</td>
+
</tr>
   </tr>
+
<tr>
   <tr>
+
<td> boolean getVisible(String objName, int view)</td>
    <td>double getValue(String objName)</td>
+
<td style="text-align: center;">4.2</td>
    <td style="text-align: center;">3.2</td>
+
<td>Returns true or false depending on whether the object is visible in Graphics View 'view' (1 or 2). Returns false if the object does not exist.</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>
+
</tr>
    </td>
+
<tr>
   </tr>
+
<td> String getValueString(String objName)</td>
   <tr>
+
<td style="text-align: center;">2.7</td>
    <td>String getColor(String objName)</td>
+
<td>Returns the value of the object with the given name as a string.</td>
    <td style="text-align: center;">2.7</td>
+
</tr>
    <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>
+
<tr>
   </tr>
+
<td>String getDefinitionString(String objName) </td>
   <tr>
+
<td style="text-align: center;">2.7</td>
    <td> boolean getVisible(String objName)</td>
+
<td>Returns the definition of the object with the given name as a string.</td>
    <td style="text-align: center;">3.2</td>
+
</tr>
    <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>
+
<td>String getCommandString(String objName)</td>
   <tr>
+
<td style="text-align: center;">2.7</td>
    <td> boolean getVisible(String objName, int view)</td>
+
<td>Returns the command of the object with the given name as a string.</td>
    <td style="text-align: center;">4.2</td>
+
</tr>
    <td>Returns true or false depending on whether the object is visible in Graphics View 'view' (1 or 2). Returns false if the object does not exist.</td>
+
<tr>
   </tr>
+
<td>String getObjectType(String objName)</td>
   <tr>
+
<td style="text-align: center;">2.7</td>
    <td> String getValueString(String objName)</td>
+
<td>Returns the type of the given object as a string (like "point", "line", "circle", etc.).</td>
    <td style="text-align: center;">2.7</td>
+
</tr>
    <td>Returns the value of the object with the given name as a string.</td>
+
<tr>
   </tr>
+
<td>boolean exists(String objName)</td>
   <tr>
+
<td style="text-align: center;">2.7</td>
    <td>String getDefinitionString(String objName) </td>
+
<td>Returns whether an object with the given name exists in the construction.</td>
    <td style="text-align: center;">2.7</td>
+
</tr>
    <td>Returns the definition of the object with the given name as a string.</td>
+
<tr>
   </tr>
+
<td>boolean isDefined(String objName)</td>
   <tr>
+
<td style="text-align: center;">2.7</td>
    <td>String getCommandString(String objName)</td>
+
<td>Returns whether the given object's value is valid at the moment.</td>
    <td style="text-align: center;">2.7</td>
+
</tr>
    <td>Returns the command of the object with the given name as a string.</td>
+
<tr>
   </tr>
+
<td>String [] getAllObjectNames()<br>
   <tr>
+
<small style="font-style: italic; font-weight: bold;">Deprecated since 3.0</small> </td>
    <td>String getObjectType(String objName)</td>
+
<td style="text-align: center;">2.7</td>
    <td style="text-align: center;">2.7</td>
+
<td>Returns an array with all object names in the construction.
    <td>Returns the type of the given object as a string (like "point", "line", "circle", etc.).</td>
 
   </tr>
 
   <tr>
 
    <td>boolean exists(String objName)</td>
 
    <td style="text-align: center;">2.7</td>
 
    <td>Returns whether an object with the given name exists in the construction.</td>
 
   </tr>
 
   <tr>
 
    <td>boolean isDefined(String objName)</td>
 
    <td style="text-align: center;">2.7</td>
 
    <td>Returns whether the given object's value is valid at the moment.</td>
 
   </tr>
 
   <tr>
 
    <td>String [] getAllObjectNames()<br>
 
    <small style="font-style: italic; font-weight: bold;">Deprecated since 3.0</small> </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>
 
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>int getObjectNumber()</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Returns the number of objects in the construction.</td>
+
<td>Returns the number of objects in the construction.</td>
   </tr>
+
</tr>
  <tr>
+
<tr>
    <td>String getObjectName(int i)</td>
+
<td>String getObjectName(int i)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Returns the name of the n-th object of the construction.</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>String getLayer(String objName)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Returns the layer of the object.</td>
+
<td>Returns the layer of the object.</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>int getLineStyle(String objName)</td>
+
<td>int getLineStyle(String objName)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Gets the line style for the object (0 to 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>int getLineThickness(String objName)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Gets the thickness of the line (1 to 13)</td>
+
<td>Gets the thickness of the line (1 to 13)</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>int getPointStyle(String objName)</td>
+
<td>int getPointStyle(String objName)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</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>
+
<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>int getPointSize(String objName)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Gets the size of a point (from 1 to 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>double getFilling(String objName)</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Gets the filling of an object (from 0 to 1)</td>
+
<td>Gets the filling of an object (from 0 to 1)</td>
   </tr>
+
</tr>
 
</table>
 
</table>
  
第358行: 第322行:
  
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
  <tr>
+
<tr>
    <th>函數</th>
+
<th>函數</th>
    <th style="text-align: center;">版本</th>
+
<th style="text-align: center;">版本</th>
    <th style="font-weight: bold;">說明</th>
+
<th style="font-weight: bold;">說明</th>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void {{Key|setMode|blue}}( int [[參考:工具編號|工具編號]] )</td>
+
<td>void {{Key|setMode|blue}}( int [[參考:工具編號|工具編號]] )</td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">2.7</td>
    <td>設定繪圖區要使用的工具<br />
+
<td>設定繪圖區要使用的工具<br />
 
 請參閱:[[參考:工具編號|工具編號]] 與 [[參考:Applet_參數|applet 參數]]中的「showToolBar」、「customToolBar」參數</td>
 
 請參閱:[[參考:工具編號|工具編號]] 與 [[參考:Applet_參數|applet 參數]]中的「showToolBar」、「customToolBar」參數</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void openFile(String strURL)</td>
+
<td>void openFile(String strURL)</td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">2.7</td>
    <td>Opens a construction from a&nbsp; file (given as absolute or relative URL string)</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>void reset()</td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">2.7</td>
    <td>Reloads the initial construction (given in filename parameter) of this applet.<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>void refreshViews()</td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">2.7</td>
    <td>Refreshs all views. Note: this clears all traces in the graphics window.</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>void setOnTheFlyPointCreationActive(boolean flag)<br>
    </td>
+
</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</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>
+
<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>void hideCursorWhenDragging(boolean flag)<br>
    </td>
+
</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Hides (true) or shows (false) the mouse cursor (pointer) when dragging an object to change the construction. </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>void setRepaintingActive(boolean flag)<br>
    </td>
+
</td>
    <td style="text-align: center;">2.7</td>
+
<td style="text-align: center;">2.7</td>
    <td>Turns the repainting of this applet on (true) or off (false).
+
<td>Turns the repainting of this applet on (true) or off (false).
 
Note: use this method for efficient repainting when you invoke several methods.</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>void setErrorDialogsActive(boolean flag)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Turns showing of error dialogs on (true) or off (false). Note: this is especially useful together with 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>void setCoordSystem(double xmin, double xmax, double ymin, double ymax)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Sets the Cartesian coordinate system of the graphics window.</td>
+
<td>Sets the Cartesian coordinate system of the graphics window.</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void setAxesVisible(boolean xAxis, boolean yAxis)</td>
+
<td>void setAxesVisible(boolean xAxis, boolean yAxis)</td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Shows or hides the x- and y-axis of the coordinate system in the graphics window.</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>void setGridVisible(boolean flag) </td>
    <td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
    <td>Shows or hides the coordinate grid in the graphics window.</td>
+
<td>Shows or hides the coordinate grid in the graphics window.</td>
   </tr>
+
</tr>
 
</table>
 
</table>
  
第431行: 第395行:
 
 當使用這些指令時,請記得一定要在<code><applet></code>標籤的最後面加入 {{Key|MAYSCRIPT|blue}} 這個屬性才行。例如:
 
 當使用這些指令時,請記得一定要在<code><applet></code>標籤的最後面加入 {{Key|MAYSCRIPT|blue}} 這個屬性才行。例如:
  
<code><applet name="ggbApplet" code="geogebra.GeoGebraApplet" codebase="." archive="geogebra.jar" width="500" height="250" {{Key|MAYSCRIPT|blue}}></code>
+
*<code><applet name="ggbApplet" code="geogebra.GeoGebraApplet" codebase="." archive="geogebra.jar" width="500" height="250" {{Key|MAYSCRIPT|blue}}></code>
  
 
 反過來說,如果我們只是要使用 <code>document.ggbApplet</code> 的物件方法去操控 Applet 中的物件時,這個 {{Key|MAYSCRIPT|blue}} 屬性就不需要設定了。
 
 反過來說,如果我們只是要使用 <code>document.ggbApplet</code> 的物件方法去操控 Applet 中的物件時,這個 {{Key|MAYSCRIPT|blue}} 屬性就不需要設定了。
第439行: 第403行:
 
* 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])
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
<tr>
+
<tr>
<th>Method Signature</th>
+
<th> 函數</th>
<th style="text-align: center;">Since</th>
+
<th style="text-align: center;"> 版本</th>
<th style="font-weight: bold;">Description</th>
+
<th style="font-weight: bold;"> 說明</th>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void registerAddListener(String JSFunctionName)</td>
+
<td>void registerAddListener(String JSFunctionName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Registers a JavaScript function as an <span style="font-weight: bold;">add</span> listener for the applet's construction. Whenever a new object is created in the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span> is called using the name of the newly created object as its single argument. <br>
+
<td>Registers a JavaScript function as an <span style="font-weight: bold;">add</span> listener for the applet's construction. Whenever a new object is created in the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span> is called using the name of the newly created object as its single argument. <br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerAddListener("myAddListenerFunction");</span> <br>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerAddListener("myAddListenerFunction");</span> <br>
</div>
+
</div>
 
When an object "A" is created, the GeoGebra Applet will call the Javascript function<br>
 
When an object "A" is created, the GeoGebra Applet will call the Javascript function<br>
<div style="margin-left: 40px;"><span style="font-family: monospace;">myAddListenerFunction("</span><span style="font-family: monospace;">A");<br>
+
<div style="margin-left: 40px;"><span style="font-family: monospace;">myAddListenerFunction("</span><span style="font-family: monospace;">A");<br>
</span></div>
+
</span></div>
</td>
+
</td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void unregisterAddListener(String objName)</td>
+
<td>void unregisterAddListener(String objName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Removes a previously registered add listener, see <span style="font-style: italic;">registerAddListener()</span></td>
+
<td>Removes a previously registered add listener, see <span style="font-style: italic;">registerAddListener()</span></td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void registerRemoveListener(String JSFunctionName)</td>
+
<td>void registerRemoveListener(String JSFunctionName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Registers a JavaScript function as a <span style="font-weight: bold;">remove</span> listener for the applet's construction. Whenever an object is deleted from the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span> 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().<br>
+
<td>Registers a JavaScript function as a <span style="font-weight: bold;">remove</span> listener for the applet's construction. Whenever an object is deleted from the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span> 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().<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerRemoveListener("myRemoveListenerFunction");</span> </div>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerRemoveListener("myRemoveListenerFunction");</span> </div>
 
When the object "A" is deleted, the GeoGebra Applet will call the Javascript function<br>
 
When the object "A" is deleted, the GeoGebra Applet will call the Javascript function<br>
<div style="margin-left: 40px;"><span style="font-family: monospace;">myRemoveListenerFunction</span><span style="font-family: monospace;">("</span><span style="font-family: monospace;">A");<br>
+
<div style="margin-left: 40px;"><span style="font-family: monospace;">myRemoveListenerFunction</span><span style="font-family: monospace;">("</span><span style="font-family: monospace;">A");<br>
</span></div>
+
</span></div>
</td>
+
</td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void unregisterRemoveListener(String objName)</td>
+
<td>void unregisterRemoveListener(String objName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Removes a previously registered remove listener, see <span style="font-style: italic;">registerRemoveListener()</span></td>
+
<td>Removes a previously registered remove listener, see <span style="font-style: italic;">registerRemoveListener()</span></td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void registerUpdateListener(String JSFunctionName)</td>
+
<td>void registerUpdateListener(String JSFunctionName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Registers a JavaScript function as a <span style="font-weight: bold;">update</span> listener for the applet's construction. Whenever any object is updated in the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span>is 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.<br>
+
<td>Registers a JavaScript function as a <span style="font-weight: bold;">update</span> listener for the applet's construction. Whenever any object is updated in the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span>is 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.<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerUpdateListener("myUpdateListenerFunction");</span> </div>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerUpdateListener("myUpdateListenerFunction");</span> </div>
 
When the object "A" is updated, the GeoGebra Applet will call the Javascript function<br>
 
When the object "A" is updated, the GeoGebra Applet will call the Javascript function<br>
<div style="margin-left: 40px;"><span style="font-family: monospace;">myUpdateListenerFunction</span><span style="font-family: monospace;">("</span><span style="font-family: monospace;">A");<br>
+
<div style="margin-left: 40px;"><span style="font-family: monospace;">myUpdateListenerFunction</span><span style="font-family: monospace;">("</span><span style="font-family: monospace;">A");<br>
</span></div>
+
</span></div>
</td>
+
</td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void unregisterUpdateListener(String objName)</td>
+
<td>void unregisterUpdateListener(String objName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Removes a previously registered update listener, see <span style="font-style: italic;">registerUpdateListener()</span></td>
+
<td>Removes a previously registered update listener, see <span style="font-style: italic;">registerUpdateListener()</span></td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void registerObjectUpdateListener(String objName, String JSFunctionName)</td>
+
<td>void {{Key|registerObjectUpdateListener|blue}}( 物件名, 函數名)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Registers a JavaScript function as an <span style="font-weight: bold;">update</span> listener for a single object. Whenever the object with the given name is updated, the JavaScript function <span style="font-style: italic;">JSFunctionName</span>is 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().<br>
+
<td> 設定當某物件的屬性有所變更時的處理程序。例如:如果設定<br />
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
+
*<code>document.ggbApplet.{{Key|registerObjectUpdateListener|blue}}("A", "updateCoords")</code><br />
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerObjectUpdateListener("A", "</span><span style="font-family: monospace;">myAupdateListenerFunction</span><span style="font-family: monospace;">");</span> <br>
+
 
  </div>
+
  則當物件 有所變更時,便會執行 <code>updateCoords("A")</code這個程序。
Whenever the object A is updated, the GeoGebra Applet will call the Javascript function<br>
 
  <div style="margin-left: 40px;"><span style="font-family: monospace;"></span><span style="font-family: monospace;">myAupdateListenerFunction</span><span style="font-family: monospace;"></span><span style="font-family: monospace;">("A");<br>
 
  </span></div>
 
Note: an object update listener will still work after an object is renamed.<span style="font-family: monospace;"></span>
 
 
</td>
 
</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td>void unregisterObjectUpdateListener(String objName)</td>
+
<td>void unregisterObjectUpdateListener(String objName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Removes a previously registered object update listener of the object with the given name, see <span style="font-style: italic;">registerObjectUpdateListener()</span></td>
+
<td>Removes a previously registered object update listener of the object with the given name, see <span style="font-style: italic;">registerObjectUpdateListener()</span></td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void registerRenameListener(String JSFunctionName)</td>
+
<td>void registerRenameListener(String JSFunctionName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Registers a JavaScript function as a <span style="font-weight: bold;">rename</span> listener for the applet's construction. Whenever an object is renamed in the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span> is called using the old name and the new name of the renamed object as its two arguments. <br>
+
<td>Registers a JavaScript function as a <span style="font-weight: bold;">rename</span> listener for the applet's construction. Whenever an object is renamed in the GeoGebraApplet's construction, the JavaScript function <span style="font-style: italic;">JSFunctionName</span> is called using the old name and the new name of the renamed object as its two arguments. <br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerRenameListener("myRenameListenerFunction");</span> </div>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerRenameListener("myRenameListenerFunction");</span> </div>
 
When an object "A" is renamed to "B", the GeoGebra Applet will call the Javascript function<br>
 
When an object "A" is renamed to "B", the GeoGebra Applet will call the Javascript function<br>
<div style="margin-left: 40px;"><span style="font-family: monospace;">myRenameListenerFunction</span><span style="font-family: monospace;">("</span><span style="font-family: monospace;">A", "B");<br>
+
<div style="margin-left: 40px;"><span style="font-family: monospace;">myRenameListenerFunction</span><span style="font-family: monospace;">("</span><span style="font-family: monospace;">A", "B");<br>
</span></div>
+
</span></div>
</td>
+
</td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void unregisterRenameListener(String objName)</td>
+
<td>void unregisterRenameListener(String objName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Removes a previously registered rename listener, see <span style="font-style: italic;">registerRenameListener()</span></td>
+
<td>Removes a previously registered rename listener, see <span style="font-style: italic;">registerRenameListener()</span></td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void registerClearListener(String JSFunctionName)</td>
+
<td>void registerClearListener(String JSFunctionName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Registers a JavaScript function as a <span style="font-weight: bold;">clear</span> 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().<br>
+
<td>Registers a JavaScript function as a <span style="font-weight: bold;">clear</span> 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().<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<span style="font-style: italic;">Example</span>: First, register a listening JavaScript function:<br>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerClearListener("myClearListenerFunction");</span> </div>
 
<div style="margin-left: 40px;"><span style="font-family: monospace;">ggbApplet.registerClearListener("myClearListenerFunction");</span> </div>
 
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<br>
 
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<br>
<div style="margin-left: 40px;"><span style="font-family: monospace;">myClearListenerFunction</span><span style="font-family: monospace;">(</span><span style="font-family: monospace;">);</span></div>
+
<div style="margin-left: 40px;"><span style="font-family: monospace;">myClearListenerFunction</span><span style="font-family: monospace;">(</span><span style="font-family: monospace;">);</span></div>
</td>
+
</td>
</tr>
+
</tr>
<tr>
+
<tr>
<td>void unregisterClearListener(String JSFunctionName)</td>
+
<td>void unregisterClearListener(String JSFunctionName)</td>
<td style="text-align: center;">3.0</td>
+
<td style="text-align: center;">3.0</td>
<td>Removes a previously registered clear listener, see <span style="font-style: italic;">registerClearListener()</span></td>
+
<td>Removes a previously registered clear listener, see <span style="font-style: italic;">registerClearListener()</span></td>
</tr>
+
</tr>
 
</table>
 
</table>
  
= GeoGebra's XML format =
+
= GeoGebra XML =
 
+
GeoGebra 檔案 (*.ggb, *.ggt) 內部是以 XML 的格式儲存的,利用下列的指令可以讓我們任意更改 GGB 檔內部的物件屬性。因此,如果上面所提到的所有指令都不能符合你的需求的話,這時就可以考慮利用下列的指令,但前提是你必須有點了解 [[:en:Reference:Xml|XML]] 格式才行。
With these methods you can set everything in a construction (see [[Reference:Xml|XML Reference]] ).
+
{{Script|evalXML| XML 字串 |無|ggbApplet.{{Key|evalXML|red}}('&lt;ELEMENT&gt;...&lt;/ELEMENT&gt;');|解析「XML 字串」,並產生或變更相對應的物件。注意:此指令不會清除已有的物件。}}
<table style="width: 100%;" class="pretty">
+
{{Script|setXML| XML 字串 |無|ggbApplet.{{Key|setXML|red}}();|解析「XML 字串」,並產生產生新的構圖。注意:此指令{{Key|會清除|red}}已有的物件。}}
   <tr>
+
{{Script|getXML| |整個構圖案本的 XML 字串|ggbApplet.{{Key|getXML|red}}();|此指令可用來儲存現有的構圖。}}
    <th>Method Signature</th>
+
{{Script|getXML|物件名稱|該物件的 &lt;ELEMENT&gt; 標籤|ggbApplet.{{Key|getXML|red}}('A');|}}
    <th style="text-align: center;">Since</th>
+
{{Script|getAlgorithmXML|物件名稱|若為自變物件,則傳回「空字串」。若為應變物件,則傳回其演算法與相關輸出物件之 XML 。|ggbApplet.{{Key|getAlgorithmXML|red}}('A');|}}
    <th>Description</th>
 
   </tr>
 
   <tr>
 
    <td>void evalXML(String xmlString) </td>
 
    <td style="text-align: center;">2.7</td>
 
    <td>Evaluates the given XML string and changes the current construction. Note: the construction is NOT cleared before evaluating the XML string.
 
    </td>
 
   </tr>
 
   <tr>
 
    <td>void setXML(String xmlString) </td>
 
    <td style="text-align: center;">2.7</td>
 
    <td>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.
 
    </td>
 
   </tr>
 
   <tr>
 
    <td>String getXML()<br>
 
    </td>
 
    <td style="text-align: center;">2.7</td>
 
    <td>Returns the current construction in GeoGebra's XML format. This method could be used to save constructions.<br>
 
    </td>
 
   </tr>
 
  <tr>
 
    <td>String getXML(String objName)<br>
 
    </td>
 
    <td style="text-align: center;">3.2</td>
 
    <td>Returns the GeoGebra XML string for the given object, i.e. only the &lt;element&gt; tag is returned.
 
    </td>
 
   </tr>
 
<tr>
 
    <td>String getAlgorithmXML(String objName)<br>
 
    </td>
 
    <td style="text-align: center;">3.2</td>
 
    <td>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.
 
    </td>
 
   </tr>
 
</table>
 
  
 
= Miscellaneous =
 
= Miscellaneous =
第592行: 第516行:
  
 
<table style="width: 100%;" class="pretty">
 
<table style="width: 100%;" class="pretty">
   <tr>
+
<tr>
    <th>Method Signature</th>
+
<th>Method Signature</th>
    <th>Since</th>
+
<th>Since</th>
    <th>Description</th>
+
<th>Description</th>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>String evalMathPiper(String string) </td>
+
<td>String evalMathPiper(String string) </td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Passes the string to MathPiper and returns the result as a String.<br>
+
<td>Passes the string to MathPiper and returns the result as a String.<br>
 
<b>Removed in GeoGebra 4.0 and will replaced with evalGeoGebraCAS() in GeoGebra 4.2</b>
 
<b>Removed in GeoGebra 4.0 and will replaced with evalGeoGebraCAS() in GeoGebra 4.2</b>
    </td>
+
</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>String getIPAddress()</td>
+
<td>String getIPAddress()</td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Returns the IP address of the local computer as a String eg "192.168.0.4"
+
<td>Returns the IP address of the local computer as a String eg "192.168.0.4"
    </td>
+
</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>String getHostname() </td>
+
<td>String getHostname() </td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Returns the hostname of the local computer as a String
+
<td>Returns the hostname of the local computer as a String
    </td>
+
</td>
   </tr>
+
</tr>
   <tr>
+
<tr>
    <td>void debug(String string) </td>
+
<td>void debug(String string) </td>
    <td style="text-align: center;">3.2</td>
+
<td style="text-align: center;">3.2</td>
    <td>Prints the string to the Java Console
+
<td>Prints the string to the Java Console
    </td>
+
</td>
   </tr>
+
</tr>
  
 
</table>
 
</table>
[[en:Reference:JavaScript]]
 
 
[[Category:參考]]
 
[[Category:參考]]
 +

2013年4月15日 (一) 04:25的最新版本

GGB 檔中使用 JavaScript

物件的 OnClick 事件

如果在物件的「程式」頁面中要使用 JavaScript 來控制 GGB 的話,可以使用 ggbApplet 這個關鍵字,然後用下面介紹的各種 JavaScript 指令。

範例: 如果我們在一個物件的 OnClick 事件中輸入以下的程式碼,則當此物件被滑鼠按到時,會自動產生一個數列。

var a = ggbApplet; a.evalCommand('n = 3'); a.evalCommand('s = Sequence[k^2, k, 1, n]');

備註: 在 GeoGebra 內部使用 JavaScript 宣告 ggbApplet 的時候,要使用:

var a = ggbApplet; 不能使用: var a = document.ggbApplet; 否則會產生「document 物件不存在」的錯誤!

網頁中使用 JavaScript

範例: 下面的 HTML 網頁碼會在網頁中產生一個「按鈕」,按下此鈕時,繪圖區會回到初始狀態。

<input type="button" value="重設" onclick="document.applets[0].reset();">

範例: 下面的 HTML 網頁碼會產生兩個「按鈕」,第一個可以隱藏 A 點,第二個可以顯示 A 點。

<input type="button" value="隱藏 A 點" onclick="document.applets[0].setVisible('A', false);"> <input type="button" value="顯示 A 點" onclick="document.applets[0].setVisible('A', true);">

範例: 下面的 HTML 網頁碼會產生一個「按鈕」,按下此鈕時,會畫出 AB 兩點,與通過此兩點的直線。

<applet name="ggbApplet" ... > </applet> ...... <script type="text/javascript"> function drawLineAB() { var applet = document.ggbApplet; applet.evalCommand("A = (1,1)"); applet.evalCommand("B = (3,2)"); applet.evalCommand("s = Line[A, B]"); } </script> ...... <input type="button" value="Do construction" onclick="drawLineAB();">

Note 提示: 請打開下面網頁的原始碼,你就可以看到如過透過 JavaScript 來控制 GGB 的實際例子。
Note 提示: 下面的網頁用來示範「事件處理」的概念。當我們利用作圖工具產生新物件時,網頁中所設定的「新增物件處理器」會檢查你的作圖是否已經完成,然後給你適當的回應。
Note 提示: 下面是一個利用 JavaScript 產生互動效果的例子。網頁開啟後,會隨機畫一條直線,你必須填入正確的「斜率」,如果回答正確,它會再隨機畫另一條直線讓你回答它的斜率。

通用指令

Script24x24.png evalCommand ( 命令字串 )


回傳:若執行成功則傳回 true,若失敗則傳回 false
範例:{{{4}}}
說明:此指令會執行「命令字串」中所指定的 GGB 指令,此與直接在「命令列」中下該指令有相同的效果。從 3.2 版起,我們可以在「命令字串」中加入特殊的換行字串「\n」,這樣一來,我們就可以同時下許多個指令。

Script24x24.png setUndoPoint ( )


回傳:無。
範例:{{{4}}}
說明:此指令可用於設定由 evalCommand() 所產生的動作的回復點。

設定物件屬性

函數 版本 說明
void deleteObject(String objName) 2.7 Deletes the object with the given name.
void setValue(String objName, double value) 3.2 Sets the double value of the object with the given name. Note: if the specified object is boolean, use a value of 1 to set it to true and any other value to set it to false. For any other object type, nothing is done.
void setCoords(String objName, double x, double y) 3.0 Sets the coordinates of the object with the given name. Note: if the specified object is not a point or a vector, nothing is done.
void setColor(物件名, 紅, 綠, 藍) 2.7 設定物件的顏色,紅綠藍 (RGB) 的顏色值為 0 ~ 255
例如:document.ggbApplet.setColor("lineAB", 255, 0, 0)
void setVisible(String objName, boolean visible) 2.7 Shows or hides the object with the given name in the graphics window.
void setLabelVisible(String objName, boolean visible) 3.0 Shows or hides the label of the object with the given name in the graphics window.
void setLabelStyle(String objName, int style) 3.0 Sets the label style of the object with the given name in the graphics window. Possible label styles are NAME = 0, NAME_VALUE = 1, VALUE = 2 and (from GeoGebra 3.2) CAPTION = 3
void setFixed(String objName, boolean flag) 3.0 Sets the fixed state of the object with the given name. Note: fixed objects cannot be changed.
void setTrace(String objName, boolean flag) 3.0 Turns the trace of the object with the given name on or off.
boolean renameObject(String oldObjName, String newObjName) 3.2 Renames oldObjName to newObjName. Returns whether the rename was successful
void setLayer(String objName, int layer) 3.2 Sets the layer of the object
void setLayerVisible(int layer, boolean visible) 3.2 Shows or hides the all objects in the given layer
void setLineStyle(物件名, 樣式編號) 3.2 設定線條樣式:0 - 實線,1 - 長虛線,2 - 短虛線,3 - 點虛線,4 - 長點虛線。
void setLineThickness(物件名, 厚度) 3.2 設定物件(線、圓等)的厚度,值從 1 ~ 13
void setPointStyle(String objName, int style) 3.2 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))
void setPointSize(String objName, int size) 3.2 Sets the size of a point (from 1 to 9)
void setFilling(String objName, double filling) 3.2 Sets the filling of an object (from 0 to 1)
String getPNGBase64(double exportScale, boolean transparent, double DPI) 4.0 Returns Graphics View 1 as a base64-encoded String
eg var str = ggbApplet.getPNGBase64(1, true, 72);
boolean writePNGtoFile(String filename, double exportScale, boolean transparent, double DPI) 4.0 Exports Graphics View 1 to a .PNG file (signed applets only)
eg var success = ggbApplet.writePNGtoFile("c:\\test.png", 1, false, 300);
boolean isIndependent(String objName) 4.0 checks if objName is independent
boolean isMoveable(String objName) 4.0 checks if objName is is moveable
String getBase64() 4.0 Gets the current construction as a base64-encoded .ggb file
void setBase64(String) 4.0 Sets the current construction from a base64-encoded .ggb file

設定動態效果

函數 版本 說明
setAnimating 3.2 格式:setAnimating( 物件名, 啟動動畫? )
備註: 設定物件要不要啟動動畫效果。
範例: setAnimating("A", true)
注意 注意: 光使用此函數並不能使物件產生動畫效果,必須搭配 startAnimation() 才行!
setAnimationSpeed 3.2 格式:setAnimationSpeed(物件名, 速度)
備註: 設定物件的動畫速度。
startAnimation 3.2 格式:startAnimation()
備註: 正式啟動動畫功能。注意:只有用過 setAnimating() 設定過的物件才會動喔!
void stopAnimation() 3.2 Stops animation for all objects with the animating flag set, see setAnimating()
boolean isAnimationRunning() 3.2 Returns whether automatic animation is currently running.

取得物件屬性

Script24x24.png getXcoord ( 物件名稱 )


回傳:物件的 x 座標。若物件不是點或向量,則傳回 0。
範例:{{{4}}}

Script24x24.png getYcoord ( 物件名稱 )


回傳:物件的 y 座標。若物件不是點或向量,則傳回 0。
範例:{{{4}}}

Script24x24.png getValue ( 物件名稱 )


回傳:物件的數值、長度、面積等。若物件為「真假值」,則 true 傳回 1,false 傳回 0。
範例:{{{4}}}

Method Signature Since Description
String getColor(String objName) 2.7 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.
boolean getVisible(String objName) 3.2 Returns true or false depending on whether the object is visible in the Graphics View. Returns false if the object does not exist.
boolean getVisible(String objName, int view) 4.2 Returns true or false depending on whether the object is visible in Graphics View 'view' (1 or 2). Returns false if the object does not exist.
String getValueString(String objName) 2.7 Returns the value of the object with the given name as a string.
String getDefinitionString(String objName) 2.7 Returns the definition of the object with the given name as a string.
String getCommandString(String objName) 2.7 Returns the command of the object with the given name as a string.
String getObjectType(String objName) 2.7 Returns the type of the given object as a string (like "point", "line", "circle", etc.).
boolean exists(String objName) 2.7 Returns whether an object with the given name exists in the construction.
boolean isDefined(String objName) 2.7 Returns whether the given object's value is valid at the moment.
String [] getAllObjectNames()
Deprecated since 3.0
2.7 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.
int getObjectNumber() 3.0 Returns the number of objects in the construction.
String getObjectName(int i) 3.0 Returns the name of the n-th object of the construction.
String getLayer(String objName) 3.2 Returns the layer of the object.
int getLineStyle(String objName) 3.2 Gets the line style for the object (0 to 4)
int getLineThickness(String objName) 3.2 Gets the thickness of the line (1 to 13)
int getPointStyle(String objName) 3.2 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))
int getPointSize(String objName) 3.2 Gets the size of a point (from 1 to 9)
double getFilling(String objName) 3.2 Gets the filling of an object (from 0 to 1)

繪圖區指令

函數 版本 說明
void setMode( int 工具編號 ) 2.7 設定繪圖區要使用的工具
請參閱:工具編號applet 參數中的「showToolBar」、「customToolBar」參數
void openFile(String strURL) 2.7 Opens a construction from a  file (given as absolute or relative URL string)
void reset() 2.7 Reloads the initial construction (given in filename parameter) of this applet.
void refreshViews() 2.7 Refreshs all views. Note: this clears all traces in the graphics window.
void setOnTheFlyPointCreationActive(boolean flag)
3.2 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.
void hideCursorWhenDragging(boolean flag)
3.2 Hides (true) or shows (false) the mouse cursor (pointer) when dragging an object to change the construction.
void setRepaintingActive(boolean flag)
2.7 Turns the repainting of this applet on (true) or off (false). Note: use this method for efficient repainting when you invoke several methods.
void setErrorDialogsActive(boolean flag) 3.0 Turns showing of error dialogs on (true) or off (false). Note: this is especially useful together with evalCommand().
void setCoordSystem(double xmin, double xmax, double ymin, double ymax) 3.0 Sets the Cartesian coordinate system of the graphics window.
void setAxesVisible(boolean xAxis, boolean yAxis) 3.0 Shows or hides the x- and y-axis of the coordinate system in the graphics window.
void setGridVisible(boolean flag) 3.0 Shows or hides the coordinate grid in the graphics window.

由 Applet 下達 JavaScript 指令

下表的指令讓我們可以從 Applet 中的物件所產生的「事件」,下達一般的 JavaScript 指令。 當使用這些指令時,請記得一定要在<applet>標籤的最後面加入 MAYSCRIPT 這個屬性才行。例如:

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

反過來說,如果我們只是要使用 document.ggbApplet 的物件方法去操控 Applet 中的物件時,這個 MAYSCRIPT 屬性就不需要設定了。

For example, these methods can be used to:

函數 版本 說明
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(物件名, 函數名) 3.0 設定當某物件的屬性有所變更時的處理程序。例如:如果設定
  • document.ggbApplet.registerObjectUpdateListener("A", "updateCoords")

則當物件 A 有所變更時,便會執行 updateCoords("A") 這個程序。

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 的 XML 碼

GeoGebra 檔案 (*.ggb, *.ggt) 內部是以 XML 的格式儲存的,利用下列的指令可以讓我們任意更改 GGB 檔內部的物件屬性。因此,如果上面所提到的所有指令都不能符合你的需求的話,這時就可以考慮利用下列的指令,但前提是你必須有點了解 XML 格式才行。

Script24x24.png evalXML ( XML 字串 )


回傳:無
範例:{{{4}}}
說明:解析「XML 字串」,並產生或變更相對應的物件。注意:此指令不會清除已有的物件。

Script24x24.png setXML ( XML 字串 )


回傳:無
範例:{{{4}}}
說明:解析「XML 字串」,並產生產生新的構圖。注意:此指令會清除已有的物件。

Script24x24.png getXML ( )


回傳:整個構圖案本的 XML 字串
範例:{{{4}}}
說明:此指令可用來儲存現有的構圖。

Script24x24.png getXML ( 物件名稱 )


回傳:該物件的 <ELEMENT> 標籤
範例:{{{4}}}

Script24x24.png getAlgorithmXML ( 物件名稱 )


回傳:若為自變物件,則傳回「空字串」。若為應變物件,則傳回其演算法與相關輸出物件之 XML。
範例:{{{4}}}

Miscellaneous

Method Signature Since Description
String evalMathPiper(String string) 3.2 Passes the string to MathPiper and returns the result as a String.

Removed in GeoGebra 4.0 and will replaced with evalGeoGebraCAS() in GeoGebra 4.2

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