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: st@lk3r on March 14, 2009, 10:17:56 pm



Title: Is it possible to instanciate objects (java obj) in Ejs from custom code?
Post by: st@lk3r on March 14, 2009, 10:17:56 pm
I would like to know if it is possible to instanceate (create them with the "new" constructor) java objects (like drawables,containers) in the custom code pages of ejs, or at least can i import in Ejs classes that do so? e.g. create a class "charge" that extends the Drawable object, import it in a Ejs-created Model-View-Control app and  by pressing one of the View's buttons to add a "charge" in the View's DrawingFrame. More details-> Book->Open Source Physics, chapter 10, Electrodynamics (Gould et al.)


Title: Re: Is it possible to instanciate objects (java obj) in Ejs from custom code?
Post by: Fu-Kwun Hwang on March 14, 2009, 10:56:22 pm
Because EJS is a java code generator, so in principle, you can do whatever can be done with java.

You will need to know the EJS build in function names which can add view elements into EJS _view.
 
If you want to have a look at some examples, you can check out xxxView.java in your output foloder.

But I never did it that way. EJS let you define variable array.
If I need to add many particles in run time, I will define an array of variables and use view or number of element property to change the number of paricles shown.

I would suggest you check out  Charged Particle and Wall  (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=864). You can add up to 500 particels and build walls in run time.
I think it is better to do it this way.  ;)


Title: Re: Is it possible to instanciate objects (java obj) in Ejs from custom code?
Post by: st@lk3r on March 17, 2009, 04:27:30 pm
That was very helpful! Thank you very much. By the way, the walls&parts app RoCKs!  :o