Hwo to "track the mouse position"

I m a java newbie, and need to write a small program to track the mouse position.
basically, it opens a small window, and tell you the current mouse x, y coordinate. when mouse moves, hte x, y changes...
by the way, how can i compile it to .exe file, after i finished coding.
i try this way, but so many errors.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class mouseWin {
public static void main(String[] args)
          protected int last_x=0, last_y=0;
          mouseMoved(MouseEvent e);
JFrame frame = new JFrame("Mike's Mouse");
JLabel X = new JLabel("x: " + last_x + "y: " + last_y);
frame.getContentPane().add(X);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
     public mouseMoved(mouseEvent e)
          last_x = e.getx();
          last_y = e.gety();

please help.
i rewrite the code, but still cannot get it work
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
public class mouseWin implements MouseMotionListener
public static void main(String[] args)
               int last_x;
               int last_y;
               last_x = 0;
               last_y = 0;
               JFrame frame = new JFrame("Mike's Mouse");
               JLabel X = new JLabel("x: " + last_x + "y: " + last_y);
          frame.getContentPane().add(X);
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               frame.pack();
               frame.setVisible(true);
     public void mouseMoved(MouseEvent e)
          last_x = e.getx();
          last_y = e.gety();
          JLabel X = new JLabel("x: " + last_x + "y: " + last_y);
}

Similar Messages

  • Easing a gotoAndStop(frame) given by the mouse position

    Hi there.
    I have an external swf loaded into the background and i want it to go to a frame according to the mouse vertical position.
    Example: when the mouse is on the bottom part of the screen the movie is in the frame 0 and when it is on the top value goes to 800.
    so far i did it like this:
    _root.onEnterFrame = function ()
{
         var frame:Number = Stage.height-_ymouse;
         bgContainer.gotoAndStop(frame);
         
}
    But somehow i need it to ease between the values given by the mouse position so that when there is a fast movement of the mouse, the swf only gradually goes to the frame equivalent to the last mouse position.
    any sugestions??
    Cheers!

    actualFrame ist not a number NaN so i can't use it to define a frame to the clip to stop..
    I just need a function that makes something like this:
    _ymouse           ---->            clip.gotoAndStop()
         1                  ---->                     1
         800              ---->                     16
         800              ---->                     26
         800              ---->                     67
         800              ---->                     135
         800              ---->                     233
         800              ---->                     358
         800              ---->                     498
         800              ---->                     571
         800              ---->                     704
         800              ---->                     731
         800              ---->                     800

  • How to display the mouse position in a mouseBehavior?

    hi guys. how do i display the position of the mouse (x or y coordinate) every time i rotate a tansformgroup using a mouseRotate?..thanks

    Specify an AWT event as your behaviour's wakeupCriterion (MOUSE_DRAGGED or MOUSE_MOVED or something) and then do something like:
    x = event.getX();
    y = event.getY();

  • Get the mouse position

    If I have a frame and some panels on the frame, it seems I should not add the mouselisteners to the frame, but the panels. Now I can receive the mouse events. But when I try to get the mouse's position, they are the position's related to each panel. How can I get the positions associated with the frame?
    Thanks!

    public class MyFrame exyends JFrame implements MouseListener
    implement all the methods of Interface MouseListener
    e.g.
    public void mouseClicked (MouseEvent e)
    System.out.println("CLICKED AT " + e.getX() + "," + e,getY());

  • Moving the player to the mouse position.

    I have a question about moving and animated player symbol to the mouse location on a MouseDown event. Right now I have it set up to do an easing so that I can control how fast the player moves to the location. Problem is that it is done with easing. I don' t like the easing because the velocity of starts really fast and then slows down before it reaches the mouseX and mouseY location. I would like just a plain ol' stroll from the player location to the mouse location on the MouseDown event. Here is my code:
    package
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class PlayerToMouse extends MovieClip
      //Declare constants
      private const EASING:Number = 0.1;
      //Declare variables
      private var _targetX:Number;
      private var _targetY:Number;
      private var _vx:Number;
      private var _vy:Number;
      public function PlayerToMouse()
       player.gotoAndStop(1);
       //Initialize variables
       _targetX = mouseX;
       _targetY = mouseY;
       _vx = 0;
       _vy = 0;
       //Add event listeners
       stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
      private function onEnterFrame(event:Event):void
       player.play();
       //Calculate the distance from the player to the mouse
       var dx:Number = _targetX - player.x;
       var dy:Number = _targetY - player.y;
       var distance = Math.sqrt(dx * dx + dy * dy);
       //Move the object if it is more than 1 pixel away from the mouse
       if (distance >= 1)
        //move the player
        _vx = (_targetX - player.x) * EASING;
        _vy = (_targetY - player.y) * EASING;
        //move the player
        player.x +=  _vx;
        player.y +=  _vy;
       else
        player.gotoAndStop(1);
        trace("Player reached target");
        removeEventListener(Event.ENTER_FRAME,onEnterFrame);
      private function onMouseDown(event:Event):void
       _targetX = mouseX;
       _targetY = mouseY;
       addEventListener(Event.ENTER_FRAME,onEnterFrame);
    Any input would be appretiated. I am a beginner and my mindset for the best coding procedure is not there yet.
    Shiim

    I didn't exactly figure in the constants of _vx and _vy, but I took a bit of your idea and created something that works to my liking. The downfall to my code is that the calculations in the onEnterFrame causes the player to not fully reach the destination, thus the animation never stops. I forced it to stop with an if statement that comes close enough to not be noticeable.
    Here is the edited code:
    if (distance >= 1)
        _vx = (dx /30);
        _vy = (dy /30);
        //move the player
        player.x +=  _vx;
        player.y +=  _vy;
        if (distance <= 15)
         _vx = 0;
         _vy = 0;
         player.gotoAndStop(4);
         removeEventListener(Event.ENTER_FRAME,onEnterFrame);
    Thanks for the input Ned.
    If anyone has any ideas to make this better, feel free to comment. I'm a beginner and can use all the advice I can get...
    Shiim

  • Photoshop CS4 is not tracking the mouse pointer when using various tools.

    We have windows 7 Pro 32 bit using adobe CS4.
    Core i5 and core i7 processor
    4GB installed RAM
    ATI 1GB 4570 Graphics card.
    Also on various other hardware spec the same error.
    The tool brush, pen or erase etc is not following the mouse pointer smoothly.  There is a delay and if you attempt to draw quickly e.g a circle you instead get a jagged linepolygon shape.  The writing is trailing the pointer by less than one second.
    We have tried installing on a pc with no other software to test if there is a conflict and get the same error.
    Can anyone advise what the resolution is.
    Thanks

    TrevorBurroughs wrote:
    Hi, I got a brand new 15" MacBook Pro a week or so back and had problems with the trackpad - when I tap to select an item the mouse pointer "bounces" off the item I'm trying to select. It happens randomly - not every time. Very irritating. Supplier got me a replacement machine, and it's doing the same thing! Is anyone else experiencing this issue? I migrated all my data and settings from my old Mac Pro (2011 model, also running Mavericks) via Time Machine - could that have an impact? Not using any non-Apple power supplies or other devices. Any input would be welcomed.
    Migrating user from one machine to another should not be a cause of your symptoms.
    Curious two machines in a row. Did this happen before you transferred data/ or di you check.
    You have 14 days to return/exchange if you are not satisfied.
    You could Try resetting NVRAM/PRAM http://support.apple.com/kb/ht1379   but I don't see it.
    Did you try making adjustments to trackpad settings
    >Sys Pref>Trackpad> Point & Click>speed

  • How to create an animation that rotates in response to the mouse position?

    Hey guys,
             I'm designing a home page that is centered around a logo. I need the logo to rotate around 360 degrees as the mouse explores the area around it. I'm attaching a quick sketch explaining the type of motion I need, a mockup of what the page might look like, and a .png file I'll be using for the logo. Please give detailed instructions, as I am somewhat new to Edge Animate. Thanks in advance, any help is MUCH appreciated!

    Thanks for the quick response! That is exactly the type of movement I need. I've placed the code into CompositionReady, replaced the var img reference, and changed the image url in the html portion. Unfortunately when I preview the animation nothing happens. The page opens with the logo and a white background, no response. Any ideas what I've done wrong? I'm assuming it's the placement of the code? I've attached a screenshot of where I placed it. Thanks in advance!

  • How to get an Image to rotate according to the position of the mouse in Muse?

    Hey guys,
             I'm designing a home page that is centered around a logo. I need the logo to rotate around 360 degrees as the mouse explores the area around it. I'm attaching a quick sketch explaining the type of motion I need, a mockup of what the page might look like, and a .png file I'll be using for the logo. Please give detailed instructions, as I am somewhat new to Muse. Thanks in advance, any help is MUCH appreciated!

    UPDATE: The movement can be made very simply in Adobe Edge Animate through the following process:
    (and then published as an Animate Deployment Package and inserted into Muse as a .oam file.)
    "   Based on this stack exchange response Edit fiddle - JSFiddle
    Place the provided script in compositionReady and change the var img reference to the name of your element.
    example: var img = sym.$("WirelosLogoTight");     "
    - Heathrowe
      Hope this helps anyone else with the same question. Here is a link to that post: How to create an animation that rotates in response to the mouse position?

  • Return the position of the mouse

    I have an application in which i want to allow users to draw
    on a set area. The problem i am having is getting the draw function
    to loop and place a circle at the mouses position on the stage. I
    only want the drawing tool to work howver if it is over a set area.
    Would appreciate sample code that, while the mouse button is
    down a circle is created every 100 milliseconds within a rectangle
    at position (0, 0) with dimensions of 320 width by 240 height,
    thanks in advance!

    Will do! Ive got the entire source file if you like, its got
    some useful stuff in it :) P.S. its designed for an adobe air
    application

  • Getting mouse position into flash from JavaScript?

    Is there a way to get mouse coordinates in a browser that is
    cross browser compatible? I am able to track the mouse coordinates
    in all browsers except FireFox (Windows). In Windows firefox I can
    track the coordinates outside of the flash object but not inside
    the flash object. I am using the below script. Any help in this
    would be greatly appreciated. Thanks in advance.
    Regards,
    Beau

    I guess the easiest way is still to use a MouseMotionListener that you could add to your top level container. You could then store the value of the last position and still be able to access it even if the mouse hasn't moved.
    You might also want to use the following method : SwingUtilities.convertPointFromScreen(Point p, Component c);

  • How to track the cursor in the MODULE POOL?

    Hello everyone,
    I have developed one module pool program. I am facing a problem in tracking the cursor position.
    Let me tell you in detail. I have display/change button on the screen. If I come in change mode and gives a invalid value to any of the field, then after pressing 'ENTER' my screen gets gray out i.e. in display mode with flashing an error message. If I press again 'ENTER' it gets in change mode by removing all the invalid entries user changed.
    Now the requirement is I want the cursor to be placed at that particular entry in that particular column, where I have got the error message for invalid value.
    Please Help me on this.
    Thanks in advance.

    Hi Ganesh,
    Use this Syntax to set cursor
    <b>SET CURSOR { { FIELD field [LINE line] [[DISPLAY] OFFSET off] }
               | { col lin } }.</b>
    Regards,
    Balavardhan.K

  • I would like to see the values from pointer mouse like cursor, i would like to put the mouse in point of graph and see the value of point!

    I want to use the mouse pointer like cursor, i want use in my graph xy, i dont like to move the cursor to see the point.
    is it possible?

    There are vi's available to read mouse position. Look for mouse in the example code section here. You can use the Position attribute of the property node of your graph to get the mouse position within the graph. You can get the range of the scales from the property node. Then it will be a bit of straightforward math to figure out the values.
    Beware that the size of the drawing area of the graph can change as the numbers in the scales get bigger or smaller! Good Luck
    Yours Sincerely
    John

  • How to change the mouse cursor icon type when mouse moves out of client area ( propertysheet) WTL?

    I got stuck with an issue in property sheet .I want to load different cursor when the mouse position is within the client area and load another when moves out of the client area.
    In the porpetysheet I added four page. In the first page when I click next I am loading cursor of IDC_WAIT type and loading IDC_ARROW when the mouse moves out of the client area.
    In the page class I triggered the event for WM_MOUSEMOVE as follow:
        MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
    LRESULT OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    if(TRUE == m_bIsNextBtnClicked)
    ::SetCursor(LoadCursor(NULL, IDC_WAIT));
    else
    ::SetCursor(LoadCursor(NULL, IDC_ARROW));
    return TRUE;
    This event is getting triggered and absolutely had no issue with this. Similarly I tried adding `MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave)` this event making an assumption that this will get triggered if the mouse moves out of the client area,  but
    this event did not get triggered at all.If this is not the mouse event to be triggered for mouseleave which event should I trigger?
    LRESULT OnMouseLeave(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    ::SetCursor(LoadCursor(NULL, IDC_ARROW));
    return TRUE;
    Now when I click Next button , **I was actually calling a function which is taking sometime to return** . Before to this function I am loading IDC_WAIT cursor i.e., 
     `::SetCursor(LoadCursor(NULL, IDC_WAIT));` . 
    Now when move the mouse cursor on to the non-client area I want to load IDC_ARROW cursor i.e., 
        ::SetCursor(LoadCursor(NULL, IDC_ARROW)); 
    When the moves on to the non-client area I am handling the mouse event in sheet derived class as follows,
    MESSAGE_HANDLER(WM_NCMOUSEMOVE, OnNCMouseMove)
    LRESULT OnNCMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    ::SetCursor(LoadCursor(NULL, IDC_ARROW));
    return 0;
    This event is not getting triggered until unless the function in the Next button event is executed.
    I want both of them to be done in parallel i.e, click Next button now hover mouse on the client area, Busy icon should come and when mouse moves out of the client area then IDC_ARROW icon should come.
    LRESULT OnWizardNext()
    ::SetCursor(LoadCursor(NULL, IDC_WAIT));
    m_bIsNextBtnIsClicked = TRUE;
    BOOL bRet = MyFun();
    m_bIsNextBtnIsClicked = FALSE;
    //Until this function(MyFun()) is executed **WM_NCMOUSEMOVE**
    //event is not getting triggered.But this event should get triggered and I
    //should be able to see the change of cursor within and out of client area.
    Can anyone kindly help me to solve this issue.
    SivaV

    Hello
    sivavuyyuru,
    For this issue, I am trying to involve someone to help look into, it might take some time and as soon as we get any result, we will tell you.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • System not sensing mouse position

    Starting today, my computer (iMac G5 PPC) no longer senses the position of my mouse pointer. For instance:
    - The dock doesn't magnify when the mouse is in it
    - None of the corners activate things like screensaver, expose, desktop
    - When I select a menu in the menu bar, moving the mouse over another menu item doesn't open that menu.
    In other words, OSX simply has no clue where my mouse pointer is located as I move it for all those neat automatic things. Yet, I can still use the mouse to click on items to make them work, then OSX knows where the mouse is.
    I've rebooted several times to no effect, but did notice something. As apps start up, the instant a window opens, OSX will sense the mouse position for that brief moment. For example, putting the mouse over the dock doesn't magnify, but when an app window appears, the dock will magnify that very instance. Moving the mouse out of the dock area doesn't unmagnify the dock, it's stuck in that state until either another window opens, causing OSX to sense the new position, or I click any mouse button which all gets OSX's attention and senses the mouse position.
    The pointer never changes when I'm over things like Links.
    Strange stuff. The mouse moves fine, it's just not being detected as it moves.
    Now, yesterday I installed a new ScanSnap scanner with the ScanSnap Manager software and Acrobat Standard ver. 7. But the mouse didn't have this behavior yesterday, or even this morning. This strange problem just appeared out of the blue mid-day today.
    I've since used Disk Utility and Onyx, and re-installed the 10.4.9 update. I switched to another user account, no difference, so it's definitely system wide.
    This doesn't stop me from using my iMac, but I just don't know how to fix this mouse issue besides a OSX re-install.

    Ok everybody, I finally got proper behavior, it's just too bad I'm not sure of the procedure.
    When I go to bed I usually run the mouse pointer to the upper left corner to activate the screensaver. Of course it didn't work. But I also knew that clicking a button causes the mouse to be sensed, so I was pushing some of the buttons while in the corner to see if I could get the screensaver going.
    Well, after doing this, everything is back to normal operation again. So, I fixed it totally by accident. Makes me wonder if there's some features that are turned on and off somehow by doing whatever it was I did up in that corner.
    Just so you know, I use a Logitech Cordless Optical Trackman. I swapped to the original Apple corded mouse but that made no difference.
    I never had a chance to try the suggestions since I just read them before posting this.
    Anyway, I hope I don't do again whatever it was that caused the behavior, but I am going to store this info in DEVONthink just in case something like this happens again.
    Anyway, it would still be interesting if someone could shed some light on this fix I accidently found. Perhaps some hidden capabilities/features? Or just dumb luck?

  • Mouse position on screen

    is there any way to get the mouses position on the screen (not a window)?
    Stephen

    Component c = (Component)e.getSource();
    Point p = e.getPoint();
    SwingUtilities.convertPointToScreen(p, c);
    System.out.println(p);

Maybe you are looking for

  • ITunes won't start up, no error message, appears in task manager

    Hi, I have been running this system since quite a while and haven't had problems with iTunes for a while. I updated to the recent version not to long ago and it worked then once or twice, I even bought a game for the iPod (Tetris)... Now iTunes doesn

  • How can I see a mail pps attachment on iPad?

    I get e-mail attachments that are pps presentations on my iPad. How can I see them?

  • HP LP2475w produces small calibrated gamut

    Summary of the issue When calibrated, the resulting ICC profile for this monitor spans a gamut that is smaller than anticipated. Monitor and settings LP2475w with panel LPL LM240WU4 F/W: GIG068 S-L0226 Backlight hours: 4760 Brightness: 21 Contrast: 8

  • Can't install add-ons on IE11

    Hi, I tried to install an add-on from my Chinese bank's website (Shanghai Pudong Development Bank) and after I get the black-ish screen prompting for authorization the website starts loading and then just hangs. I had the exact same problem trying to

  • IPad without mifi option

    If I am understanding what I've been reading, I can get the iPad and use it strickly over wifi and not use the MIFI and the extra data plan? My plans for now is to use the iPad at home, and when traveling at hotels with wifi and other wifi hot spots.