-1

The question is in this mouse movement Integer yCoords = evt.getY(); Consider the mouse as a pendulum on y Axis it goes up and down. I need to auto increment a value to yAxis from i.e stop point of the mouse to 100, but when the mouse moves back to 50, the final result should increment up to 150, and when it gets back to 100 it should be 200(auto increment with 50 again) yCoords += yCoords; doesn't do that trick

Mandar Pandit
  • 2,171
  • 5
  • 36
  • 58
Andrian
  • 7
  • 1

2 Answers2

0

I think what you are looking for is a "Robot".

Take a look at this method: http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html#mouseMove%28int,%20int%29

You should be able to pass it the coordinates desired!

Example from: Moving the cursor in Java

try {
    // These coordinates are screen coordinates
    int xCoord = 500;
    int yCoord = 500;

    // Move the cursor
    Robot robot = new Robot();
    robot.mouseMove(xCoord, yCoord);
} catch (AWTException e) {
}
Community
  • 1
  • 1
Greg Hilston
  • 2,397
  • 2
  • 24
  • 35
  • 1
    I need to be able to catch the mouse negative values from the stop position and add them to a variable – Andrian Jun 09 '14 at 12:39
  • How about getLocation in java.awt Class PointerInfo http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation%28%29 – Greg Hilston Jun 09 '14 at 12:41
  • 1
    nothing! I'll try digging docs further, thank you for the tips – Andrian Jun 09 '14 at 13:40
0

public static int result;

  int y = evt.getY();
     int i = 0;
    while (i < 1) {
        result += y;
        try {
            Thread.sleep(1000);
            i++;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }   

            for (int x = -result; x <= result; x++) {
          p.addPoint(-x , 100- (int) (50 * fSin((x / 100.0) * 2
                * Math.PI)));           
    }

            System.out.println(result);
    }

What I was basicly missing in my code was a Global Variable!! that would store the last position of Y in a certain period of time, which is 1 sec for my needs. And that var for last position of y would be a reference to count for the new Y position.

Voilla simple as that!

Andrian
  • 7
  • 1