Results 1 to 5 of 5
  1. #1
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default 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 :

    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);
                }
            }
    where POI is a static arraylist in the class InfoRunner... and i call the method isClose( ) with the mouse current coordinates in it ...


    so in the objects i have two methods:
    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);
            }
            
        }
    where i check if the mouse is close to the object ...
    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

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    In the mouse moved method are you intentionally setting x and y with getX()?

  3. #3
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    LOL ... i was tired =) I will check it now

  4. #4
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    Works fine now =) thanks =)

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are welcome. Glad to have helped. Please mark your thread solved with the thread tools at the top of the page.

Similar Threads

  1. a problem with objects
    By p0o0o0ya in forum New To Java
    Replies: 2
    Last Post: 02-02-2011, 09:32 AM
  2. Problem with Objects
    By javadam in forum New To Java
    Replies: 4
    Last Post: 01-28-2011, 12:39 AM
  3. Saving objects problem
    By BennyJass in forum Networking
    Replies: 2
    Last Post: 01-15-2011, 11:49 PM
  4. Problem with Vector of Objects
    By JavaClueless in forum New To Java
    Replies: 2
    Last Post: 11-07-2010, 04:46 AM
  5. Problem in collision between objects
    By Chetans in forum Java Gaming
    Replies: 3
    Last Post: 03-16-2010, 12:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •