Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Strange. I fixed it a little more, but now, when it gets with 2-3 pixels from the exact location, it stops.
    Last edited by crikey; 08-20-2010 at 10:49 PM.

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Here is what I did to find the problems:

    Add this before the while loop:
    System.out.println("0 preX=" + preX + ", preY="+ preY + " vs x=" + x + ", y=" + y);


    added this after the mouseMove call:
    System.out.println("2 preX=" + preX + ", preY="+ preY + " vs x=" + x + ", y=" + y);

    Added this before the mouseMove call:
    Java Code:
                if(preX == lastX && preY == lastY) {
                    System.out.println("no movement x=" + preX + ", y=" + preY);
                }
                lastX = preX;  // save to see if we are moving
                lastY = preY;
    Then need to define the two variables before the loop:
    int lastX = -1, lastY = -1;

    Changed the while condition to:
    while ((preX != x) || (preY != y)) {

    Because the mouse was at a different location every time you start the program, there is a problem with always changing x and y by 2.
    Last edited by Norm; 08-20-2010 at 11:31 PM.

  3. #23
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Ah okay! Thanks Norm so much! It works like a charm now. I really appreciate your help :)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Mouse
    By PhQ in forum AWT / Swing
    Replies: 18
    Last Post: 08-18-2010, 05:05 PM
  2. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 05:34 AM
  3. Replies: 1
    Last Post: 08-11-2009, 04:10 PM
  4. Replies: 0
    Last Post: 11-06-2007, 03:20 PM
  5. mouse over on JButton
    By gradon in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 06:50 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
  •