![]() |
Wolfgang Christian Davidson College |
| Gregor Novak Indiana University/Purdue University Indianapolis |
|
| Evelyn Patterson U.S. Air Force Academy |
| Date/Time: Sunday, 1/5/97. 1:00pm-5:00pm | Room: MP1E |
World Wide Web HTTP protocol (hypertext transmission protocol) makes it possible to transmit multimedia documents interactively in a platform independent fashion. Hypertext markup language, HTML, documents are prepared as text documents and transmitted as text documents, yet the HTML browser displays full multimedia information (text, graphics, video and sound). The recent introduction of the Java programming language now makes it possible to add platform independent programs to this multimedia stew. Java accomplishes this trick by specifying a relatively simple virtual machine, VM, that can be implement on any computer architecture, i.e., unix, Mac, or Windows. Although this VM does not provide as rich a set of tools as the native operating system, the virtual machine can have a user interface with buttons, a drawing canvas, and other graphical elements. There may be virtue in simplicity. Small platform independent programs are ideally suited for instructional purposes such as problems. These applets can be embedded directly into HTML documents and can interact with the user using a scripting language such as JavaScript. This document demonstrates these techniques.
Preparing Java code to run inside a browser is a multi-stage process. First write the code! After the code is written, the programmer compiles it into an intermediate state called a class file. These class file are then linked into an HTML document using the <APPLET> tag. Class files are downloaded into the browser along with other objects, such as GIF images, referenced by the HTML document. It is now up to the browser to translate the machine independent class files into native binary code. Some browsers interpret and execute the java one instruction at a time. This is a slow process and would make java unsuitable for computation intensive tasks. Fortunately, browser vendors are now developing compilers that translate the class files into native machine code after downloading. These just in time, jit, compiles have the potential of making java almost as fast as optimized C++ code. The shipping version of Netscape 3.01 for Windows 95/NT includes such a compiler.
Experienced programmers may wish to browse the Netscape technical documentation for additional information.
Applets can be used effectively without additional programming (other than the required HTML tags.) For example, the first physics lab at Davidson College is an introduction to mean, standard deviation, and standard error using a 10 pennies and counting the number of heads. A Galton board java applet can make the point that repeating the number of times an experiment is performed will not change the standard deviation of the result-- although it will certainly improve the standard error.
This Applet may be embedded within your own web page with the following HTML:
<APPLET CODE="BallDrop.class" NAME="Galton" width=300 height=300> <PARAM NAME="BallImage" VALUE="smallball.gif"> <PARAM NAME="PinImage" VALUE="smallpin.gif"> <PARAM NAME="NumRows" VALUE="8"> <PARAM NAME="NumColumns" VALUE="20"> <PARAM NAME="NumBalls" VALUE="5"> <PARAM NAME="Delay" VALUE="10"> <PARAM NAME="TopSpace" VALUE="30"> <PARAM NAME="SideSpace" VALUE="20"> </APPLET>
Programmers will usually provide default values for parameters so it is often not necessary to assign each and every parameter. The class files for applet must be in the same directory (or a subdirectory if you use the CODEBASE tag) as the referring HTML document. You do not have to become a Java head to use Java applets. The Galton board applet was written by David Krider. You can find this and many other physics applets listed on the gamelan web site. Be sure and ask the authors permission to use his/her work if you are unsure about copyright. It is also a nice gesture to send a thank you for public domain applets to let the authors know that their work is appreciated.
EXERCISE: Make a copy of the Galton directory and edit the HTML file. Vary the parameters most likely to effect performance. Is it possible to bog down the Browser?
The HTML "forms" documents permit the user to submit responses ranging from checking buttons to typing in free-form text. Although these responses are can be sent back to a server for further processing, it is also possible for JavaScript to interact with Java program running on the local computer. Netscape calls this feature Live Connect. For example, a button inside a form can be used to begin animation if the Java applet has a start method:
<INPUT TYPE="button" Value="Start" NAME="startButton" onClick="document.appletName.start()">
The formName need not be the name of the class file. Rather, it is the name assigned in the APPLET tag.
EXERCISE: The Galton board applet has a start and a stop method that can be called from JavaScript. Add a form and buttons to the HTML file to start and stop the applet.
We have provided methods to read the mean and standard deviation of the balls while the Galton board is running. The ability to query the applet allows the instructor to ask a question about the statistics, obtain a student response, and then compare the student response to the actual values in the simulation.
INSTRUCTOR'S NOTE: Unfortunately, Live Connect is still beta and methods that use packages seem not to work with some combinations of Java compilers and browsers. For example, we have a parser class that can take a string, e.g. sin(pi/3), and converts this string into number. This class would be useful if instructors would like students to be able to enter valid mathematical expressions rather than just numbers. Java script could then be used to convert these strings into numbers for further processing. Unfortunately, the parser class only works with Microsoft Internet Explorer and not with Netscape.
We believe in the active learner approach. In this document we provide samples of Java applets for you to examine and embed in sample lesson plans. From a modest start one can quickly build fairly sophisticated web documents by following in the footsteps of others. Most World Wide Web sites allow users to view the source documents via the Document Source option under the View menu. This is a great way to learn how to create your own stuff, always being conscious of the copyright issues of course. In this workshop you will examine and create HTML documents using Java and JavaScript. For the most part you will be working with document templates and resources which were prepared by the workshop staff. These resources reside on your workshop workstation. You can copy as much as you wish. Don't worry if it doesn't all fit. Everything will also available for downloading on the two primary WebPhysics servers, WebPhysics.davidson.edu and WebPhysics.iupui.edu. Follow the Phoenix Workshop link. In fact, the on-line version of this workshop is much more useful than a paper version because it contains links to other Web sites. Which, of course, is the point of the world wide web.
Plotting functions in real time is straight forward with the PlotFunction applet. The HTML author can hard code functions in JavaScript and display these functions in response to user input, such as a button click. Use this applet to construct a problem that tests a student's ability to match position and velocity graphs.
INSTRUCTOR'S NOTE: The ability to send the coordinates of a mouse click from inside the PlotFunction applet to JavaScript will be added in a future release.
Samples for you to try out. Feel free to use these applets in the Java/JavaScript lessons you create in this workshop.
Essential software for html authoring on the Microsoft Windows platform.
Copyright © 1996 W. Christian All rights reserved.