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: Abyss333 on October 21, 2010, 01:44:59 am



Title: How do I get the cursor position in a running plotting panel?
Post by: Abyss333 on October 21, 2010, 01:44:59 am
Hello

I'm trying to create a "Game of Life" (John Conway) with EJS and I have the problem that I'm not able to get the cursor position in my plotting panel.
Heard something about that the position is accesable via the properties of my plotting panel but I really don't know how to put it in my algorithms because I don't know the exact methods for the positions on X-axis as well as the Y-axis.

Thanks for help.


Title: Re: How do I get the cursor position in a running plotting panel?
Post by: lookang on October 21, 2010, 12:30:46 pm
see my mx , my(http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1978.0;attach=3507;image)
mx =mouse coordinate in x
my =mouse coordinate in y

u can download it  http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1027.0 (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1027.0)

how mx, and my is used to detect the mouse position.

there are also many other applets from Professor Fu Kwun Hwang that has mx and my :)
it is one which i adapted from him.


Title: Re: How do I get the cursor position in a running plotting panel?
Post by: Fu-Kwun Hwang on October 21, 2010, 12:50:40 pm
As lookang suggested:

 Define mx,my as variables to store value for cursor position, and assigned them to "Pos x" and "Pos y"

And EJS will find cursor position and translated to current plottingPanel coordinates , and assigned value to mx,my

Normally, I  will access mx,my values from action code in "OnPress, OnDrag,OnRelease, OnEnter,OnExit"

e.g. at r=Math.sqrt(mx*mx+my*my) in OnDrag
will find distance between origin and cursor position in plottingPanel
when you click and drag mouse inside plottingPanel
 


Title: Re: How do I get the cursor position in a running plotting panel?
Post by: Abyss333 on October 21, 2010, 09:40:06 pm
Wow, thank you  ;D

That will help me alot in my EJS programming.  :D