Results 1 to 5 of 5
Thread: Objects problem ...
- 05-14-2011, 03:09 AM #1
Objects problem ...
Okey ... here is my problem ... i have a ArrayList of objects ... and i want them to check when the mouse is close to their X and Y ...
in my mouse class i have :
where POI is a static arraylist in the class InfoRunner... and i call the method isClose( ) with the mouse current coordinates in it ...Java Code:public void mouseMoved(MouseEvent e) { int mouseX = e.getX(); int mouseY = e.getX(); for (int object = 0 ; object < InfoRunner.POI.size();object++){ InfoRunner.POI.get(object).isClose(mouseX, mouseY); } }
so in the objects i have two methods:
where i check if the mouse is close to the object ...Java Code:int id; double x,y; public boolean checkClose (double tx, double ty) { double distance = Math.sqrt((x-tx)*(x-tx)+(y-ty)*(y-ty)); return distance < 10; } public void isClose(double x, double y) { if (this.checkClose(x,y)) { System.out.println("Is close to " + id); } }
I have looped trough the objects and checked the so that all info excisted and is correct ... i also added the mouseMotionListener to a panel .. and desplay a img for each object so that i know where they are...
now when i run it ... i can se all objects ... but when i drag the mouse over them i get no out print ... some times i get a out print where there is no img (images painted at the objects XY cord), and all the time it is the same out print.. and one object down in the corner of the screen works .. it says the same id that i get from the ones not near a img ...
all code that i use for this is pasted (except paintning of img)... any thoughts? Thanks
- 05-14-2011, 03:23 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
In the mouse moved method are you intentionally setting x and y with getX()?
- 05-14-2011, 04:09 PM #3
LOL ... i was tired =) I will check it now
- 05-14-2011, 04:11 PM #4
Works fine now =) thanks =)
- 05-14-2011, 04:14 PM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You are welcome. Glad to have helped. Please mark your thread solved with the thread tools at the top of the page.
Similar Threads
-
a problem with objects
By p0o0o0ya in forum New To JavaReplies: 2Last Post: 02-02-2011, 08:32 AM -
Problem with Objects
By javadam in forum New To JavaReplies: 4Last Post: 01-27-2011, 11:39 PM -
Saving objects problem
By BennyJass in forum NetworkingReplies: 2Last Post: 01-15-2011, 10:49 PM -
Problem with Vector of Objects
By JavaClueless in forum New To JavaReplies: 2Last Post: 11-07-2010, 03:46 AM -
Problem in collision between objects
By Chetans in forum Java GamingReplies: 3Last Post: 03-15-2010, 11:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks