determine the mouse cursor position without mouse event

Discussion in 'Java' started by tom arnall, Dec 18, 2006.

  1. tom arnall

    tom arnall Guest

    is there a way to determine the mouse cursor position apart from
    intercepting a mouse event such as drag, i.e., sometimes i want the cursor
    position even if no mouse event has taken place

    tom arnall
    north spit, ca
    usa



    Loosen up: the tests extend the compiler.


    --
    Posted via a free Usenet account from http://www.teranews.com
    tom arnall, Dec 18, 2006
    #1
    1. Advertising

  2. tom arnall wrote:
    > is there a way to determine the mouse cursor position apart from
    > intercepting a mouse event such as drag, i.e., sometimes i want the cursor
    > position even if no mouse event has taken place


    What about trapping "mouse move" events? Every time the mouse moves to a
    position inside your component it should generate one. If a mouse_pos
    value pair is updated by a listener for such an event, it should always
    hold the last position the mouse has had inside your component. If you
    want the pos when it's outside the component, that may not be possible.
    To know when it's left the component, just look for the pos to get near
    the edge of the component and then not change for a while.
    John Ersatznom, Dec 18, 2006
    #2
    1. Advertising

  3. tom arnall wrote:
    > is there a way to determine the mouse cursor position ...


    1.5+
    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MouseInfo.html#getPointerInfo()>
    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation()>

    Andrew T.
    Andrew Thompson, Dec 18, 2006
    #3
  4. tom arnall

    tom arnall Guest

    John Ersatznom wrote:

    > tom arnall wrote:
    >> is there a way to determine the mouse cursor position apart from
    >> intercepting a mouse event such as drag, i.e., sometimes I want the
    >> cursor position even if no mouse event has taken place

    >
    > What about trapping "mouse move" events? Every time the mouse moves to a
    > position inside your component it should generate one. If a mouse_pos
    > value pair is updated by a listener for such an event, it should always
    > hold the last position the mouse has had inside your component. If you
    > want the pos when it's outside the component, that may not be possible.
    > To know when it's left the component, just look for the pos to get near
    > the edge of the component and then not change for a while.




    That's the approach I use now: create a mouse move listener and update the
    x,y values there for when I need them. But I seems to me that's a lot of
    burden on the system, and I'm hoping that java gives more direct access to
    the info. It seems to me that java tracks the info anyway, in order to make
    the mousemove listener possible, so why not provide access to the info
    without requiring a subroutine call e'time the cursor moves a pixel.

    tom arnall
    north spit, ca
    usa

    --
    Posted via a free Usenet account from http://www.teranews.com
    tom arnall, Dec 18, 2006
    #4
  5. tom arnall

    tom arnall Guest

    Andrew Thompson wrote:

    > tom arnall wrote:
    >> is there a way to determine the mouse cursor position ...

    >
    > 1.5+
    >

    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MouseInfo.html#getPointerInfo()>
    >

    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation()>
    >


    one man's stupid question, another man's prize. thanks very much.

    --
    Posted via a free Usenet account from http://www.teranews.com
    tom arnall, Dec 18, 2006
    #5
  6. tom arnall

    tom arnall Guest

    Andrew Thompson wrote:

    > tom arnall wrote:
    >> is there a way to determine the mouse cursor position ...

    >
    > 1.5+
    >

    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MouseInfo.html#getPointerInfo()>
    >

    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation()>
    >
    > Andrew T.


    I find with MouseInfo etc that it gives the absolute position of the mouse
    cursor. For the position relative to the component on which the cursor is
    located, there is Component.getMousePosition() covered at:

    http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#getMousePosition()

    Thanks for guiding me in the right direction.

    tom arnall
    north spit, ca
    usa

    --
    Posted via a free Usenet account from http://www.teranews.com
    tom arnall, Dec 19, 2006
    #6
  7. tom arnall

    Ian Shef Guest

    tom arnall <> wrote in news:4586dd40$0$15523$88260bb3
    @free.teranews.com:

    > is there a way to determine the mouse cursor position apart from
    > intercepting a mouse event such as drag, i.e., sometimes i want the cursor
    > position even if no mouse event has taken place

    <snip>

    I believe that MouseInfo.getPointerInfo() (in java.awt) will do what you
    asked for,
    but I think that adding a MouseMotionListener (in java.awt.event) and using
    it to keep track is often a better way.

    --
    Ian Shef 805/F6 * These are my personal opinions
    Raytheon Company * and not those of my employer.
    PO Box 11337 *
    Tucson, AZ 85734-1337 *
    Ian Shef, Jan 18, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean-Benoit MORLA
    Replies:
    1
    Views:
    3,776
    Michael Borgwardt
    May 24, 2004
  2. dmaziuk
    Replies:
    3
    Views:
    569
    Chris Gonnerman
    Jan 25, 2011
  3. Danny@Kendal

    mouse cursor position

    Danny@Kendal, Nov 12, 2004, in forum: Javascript
    Replies:
    10
    Views:
    242
  4. James Black
    Replies:
    0
    Views:
    400
    James Black
    May 28, 2006
  5. Cah Sableng

    Determine cursor position on textfield

    Cah Sableng, Mar 7, 2007, in forum: Javascript
    Replies:
    3
    Views:
    137
Loading...

Share This Page