Script Builders for Physlets

PhysletBuilder is a tool for constructing Physlet  scripts that can be viewed stand-alone in a web browser. It's tested with Internet Explorer 5.5. The output is an HTML page with a JavaScript configuration for Physlets® from Davidson College. Afterwards, you can add text and modify the layout with a web editor like Namo, Frontpage, Dreamweaver... The actual program files (.jar) should be downloaded separately from the Physlet Homepage. In this case, specify the realtive path from the final location of your physlet html page to the jar files, e.g. "../classes". For online use, this relative path can be replaced by an absolute URL (http://...) that points to a web directory with the appropriate jar files.

General Instructions:

Every click on the hyperlink in the second column (e.g. "Mirror") adds a new JavaScript line for physlet configuration. Before clicking, you need to specify the parameters in the input fields of the respective row. After clicking, you can still edit the whole script in a frame below and update. Further hints for a particular method may be available when the mouse pointer hovers over the (i)-symbol at the beginning of each row.

(i)

Mirror

 x:  focal length:  chose "spherical" to show aberrations:  

yields:
id1 = document.Opticspplet.addObject("mirror","x=2.5,f=1");

As a side effect, "id1" will appear in all drop down menus for parameters that demand objects, e.g. to create " ...setDragable(id1,true)".


The default script that is displayed at start up of PhysletBuilder corresponds to a function init(), that is executed at start up of the final physlet page. You may add further scripts that will be associated with push buttons at the physlet page. If you rename or delete the init script, the physlet won't perform any action without pushing a script button.

 Script:  Rename:  Delete  New


If you want your students to enter data on the physlet page, you can provide input fields for them. They should carry default values to avoid errors if the script is executed before a student enters a value. For your script, you can use as variables all the names of input fields that appear in the drop down menu "Input:" at a given moment as though they were defined beforehand in the script.

 Input:  Rename:  Default:  Delete  New

Caution is needed if you want to use variables for parameters that appear enclosed within quotation marks. In this case, you'll have to break the respective string for the variable. For example, in order to use input fields f or xpos in addObject("mirror","x=2.5,f=1")change the script manually to:

id1 = document.Opticspplet.addObject("mirror","x="+xpos+",f=1");  or
id1 = document.Opticspplet.addObject("mirror","x=2.5,f="
+f); 


Troubleshooting:

(PhysletBuilder is tested with InternetExplorer 5.5, an may not be supported by other browsers - feed back is welcome, see below)

Applet preview fails at first pop-up with a JavaScript error message Click error message away (if needed) and push browser reload button.
"Save As" in browser menu "file" doesn't work with Applet preview: Save html source code, either by right clicking at the white background of physlet preview (if "on")  - or by selecting physlet preview "html" in PhysletBuilder and copy-paste source code from pop-up window to external text editor and save there.
object parameters display "n/a yet" instead of input fields First, you need to insert an object that introduces a variable for its ID in the script. This yields lines starting with "id...=...". Then, every such variable will be available in drop down menues for parameters that expect object IDs.
JavaScript errors in the physlet preview say that something is undefined Check the order of script lines and rearrange them manually, such that all variables xy in the script are either preceeded by their definition "xy = document..." or are mentioned in the drop down list of inputs.
JavaScript errors in the physlet preview say that something is null or no object Check if in every line "document. ..." is followed by the applet name that is specified in "PhysletBuilder for ..."
Applet field remains grey and/or a JavaScript error says that a property or method is not supported by this object The generated physlet page may not find the relative path to the jar-archives ("codebase" in html source) with the actual simulation programs. This must be changed accordingly if you don't save the physlet page in the same directory as PhysletBuilder. Also, look at the download section of the physlets homepage at Davidson College, if you've got the latest  versions of the .jar-files that are mentioned in PhysletBuilder.

Feed-back to: Frank Schweickert, University of Kaiserslautern, Germany