NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: ahmedelshfie on November 17, 2010, 07:03:12 pm

Title: Photoelectric
Post by: ahmedelshfie on November 17, 2010, 07:03:12 pm
Hello prof
Photoelectric java applet written by Jose Ignacio Fernández Palop.
URL download applet http://www.compadre.org/osp/items/detail.cfm?ID=10272
I don't know how i add the images in applet I'm talk about images that added in applet by variables , i don't know how i add this images i never use this way to add images in easy java simulation.
Could you explain how i add images by this way in EJS.
I already attach image to applet and the jar file too.

Title: How to switch images at run time for EJS simulations
Post by: Fu-Kwun Hwang on November 17, 2010, 08:39:22 pm
There is a "image File" property for user to select image file from your local file system.
It will use image file in _data/reset1.gif if the value for "image File"  is "./_data/reset1.gif"

You can define a String in EJS variable panel.
e.g. Name=image, type=String, Initial value="./_data/reset1.gif"
then assign value for "image File" as  "%image%"
EJS will find value from "image" and load the file.

You can change value of "image" with java code.
e.g. If (x>10 ) image="./_data/reset1.gif";
else image="./_data/reset2.gif";
However, you will have to make sure both files are available.

You should add both files as "User files" from "Run option" panel. (check out attached file)

It is the same feature for property value in EJS GUI elements.
You can enter value or enter a variable name. 
However, for String type property, the value is a string, so variable name are enclosed by "%" pair.

For the attached jar file:The following code were used.
    material = "photoelectric/sodio.gif";
    potencialcorte = 2.28;
    material = "photoelectric/cesio.gif";
    potencialcorte = 2.1;
and the image property was assigned with value="%material%"

Title: Re: Photoelectric
Post by: ahmedelshfie on November 17, 2010, 11:24:37 pm
Thanks prof
I have just one comment about ./ when i add this in code and variable panel ejs print message Required files not found
So l delete ./ and change to "_data/photoelectric/0.gif" i also delete from code ./ to become like it
    material = "_data/photoelectric/sodio.gif";
    potencialcorte = 2.28;
    material = "_data/photoelectric/cesio.gif";
    potencialcorte = 2.1;
So after run applet work fine and message not appear again i didn't know what the reason, but now is work fine!