Results 1 to 7 of 7
  1. #1
    G.rocks is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default Problem with determing mouse position!!!

    I've problem finding position of mouse in applet.
    I've used MouseInfo.getPointerInfo().getLocation() but it gives like +8 in x positon and +51 in y position. is it returning the position with respect to the whole window. In need the position with respect to the applet positon..

    i've also used getX() and getY() but it only return 0,0.. plz help..

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by G.rocks View Post
    I've problem finding position of mouse in applet.
    I've used MouseInfo.getPointerInfo().getLocation() but it gives like +8 in x positon and +51 in y position. is it returning the position with respect to the whole window. In need the position with respect to the applet positon..

    i've also used getX() and getY() but it only return 0,0.. plz help..
    Have you tried implementing a Mouse(Motion)Listener? Read the API documentation for those interfaces.

    kind regards,

    Jos

  3. #3
    G.rocks is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    Thanx any waz i want the postion of mouse when clicked.

    I found out the problem.. the one i'm using return the position with respect to whole window.. Is the anywaz to find the position of applet..

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    :headdesk:

    HAVE YOU TRIED IMPLEMENTING A MOUSE(MOTION)LISTENER? READ THE API DOCUMENTATION FOR THOSE INTERFACES.

    db

  5. #5
    G.rocks is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    thank any waz i've found the solution....
    Java Code:
    public void mouseClicked(MouseEvent e) {
           xpos=e.getX()-17;//MouseInfo.getPointerInfo().getLocation().x-8;
           ypos=e.getY()-34;//MouseInfo.getPointerInfo().getLocation().y-50;
           System.out.println(xpos+","+ypos);
           repaint();
        }
    just forgot to use e.getX() i used only getX()
    this might be help to other

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Darryl.Burke View Post
    :headdesk:

    HAVE YOU TRIED IMPLEMENTING A MOUSE(MOTION)LISTENER? READ THE API DOCUMENTATION FOR THOSE INTERFACES.
    It was to be expected: my reply didn'y contain any boilerplate code that could be copied and (randomly?) glued in the OP's code so it was a worthless reply so it had to be ignored ;-)

    :headdesk:

    kind regards,

    Jos

  7. #7
    Iskatel is offline Member
    Join Date
    Mar 2010
    Posts
    27
    Rep Power
    0

    Default

    Just to make a comment, (I see you are adjusting your location point); not sure how this helpful, but yesterday I had a problem with popping up a menu, if I used x and y from MouseInfo, it would come up in different place, far from mouse cursor, with: popupMenu.show(host, x, y); so I though I might need to adjust as well, but when I used: popupMenu.setInvoker(host) and popupMenu.setLocation(point), where point was location from MouseInfo it worked well.

Similar Threads

  1. Manually position JTextfield problem
    By castiel in forum AWT / Swing
    Replies: 3
    Last Post: 02-20-2010, 05:24 AM
  2. Self determing the server
    By etherkye in forum Networking
    Replies: 4
    Last Post: 06-25-2009, 11:36 PM
  3. get position in string from caret position
    By helloworld111 in forum AWT / Swing
    Replies: 5
    Last Post: 02-19-2009, 01:36 AM
  4. Replies: 0
    Last Post: 06-25-2008, 10:32 AM
  5. Use the mouse position
    By susan in forum Java Applets
    Replies: 1
    Last Post: 07-28-2007, 11:10 PM

Posting Permissions

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