-1

I need to make these arrays because I am trying to make a mouse glide from the first point to the second, the second to the third, and etc... Each glide should be broken into 25 steps and take 1000 milliseconds.

I don't know how to start the method exactly.

public void glide(int [] x, int [] y) I even have doubt that i set this method correctly. I really don't have a clue how to start this method.

user1205958
  • 75
  • 1
  • 2
  • 5

2 Answers2

0

The better approach would be to use a multi-dimensional array in order to store your values. Here is an example:

public void glide(int[][] points)
{
    // ...
}

int[][] p = new int[25][25];
// assign points
glide(p);
haiyyu
  • 2,194
  • 6
  • 22
  • 34
0

Well that method takes two arrays as parameters. So to use the glide method you should already have two arrays written. In Java you make the array by saying:

private int[] x-coords = new int[SIZE] // SIZE is how many elements will be in the array
private in[] y-coords = new int[SIZE] // They should be the same if you're using them as coordinates

then to USE the glide method you would say

glide(x-coords,y-coords);

Now as far as writing that method goes.... it's going to depend on alot of things and if you showed more of the code then that would help alot. In essence what you want to do is:

public void glide(int[] x, int[] y) {

  // Standard loop to iterate through all the elements of the x array
  for(int i=0; i<x.length; i++) {

    // This moves the pointer
    mouseMove(x[i],y[i]);

    // This pauses
    try {
      Thread.sleep(1000);
    } catch(InterruptedException e) {}

  }

}

Now what this is all doing is moving the mouse (hopefully in small increments) every 1000 milliseconds. The way you're breaking up the coordinates isn't the most effecient way (why use arrays instead of using math in the code) but it will work that way. Just requires alot more math on your part instead of the computers. Basically you're wanting to glide from the coorderinates (x[0],y[0]) to (x[24],y[24]). So the starting point is going to be the first points in the arrays and the end point is the last points in the arrays. Then every number in between should move by however much it needs to move.

The way that was presented in How to move a mouse smoothly throughout the screen by using java? is going to be the most efficient way. All he did was let the computer do the math and instead of using arrays he just put in a starting point and an ending point. You should read over that and try to understand that code as well as possible.

Community
  • 1
  • 1
CaldwellYSR
  • 3,056
  • 5
  • 33
  • 50
  • ok thanks for the start but how would you move the mouse to the xy corrdinates – user1205958 Feb 23 '12 at 06:26
  • That depends on alot of things. The question doesn't describe the situation at all. Are you supposed to actually cause the user's pointer to move? Are you just moving an image across the screen? What Java libraries are you supposed to be using (I assume this is some kind of assignment) I need more details to be able to answer correctly – CaldwellYSR Feb 23 '12 at 06:31
  • OK well Im making a robot class and I dont think this is a client program. Your just supposed to get some coordinates(x,y) and make the mouse glide to the first point then to the second. Eac glide is supposed to be broken down to 25 steps and it should take 1000 milliseconds. Thats all i need. Im sorry if you still dont understand, but thank you for trying to help me. I really need help. – user1205958 Feb 23 '12 at 06:37
  • http://stackoverflow.com/questions/9387483/how-to-move-a-mouse-smoothly-throughout-the-screen-by-using-java Looks like someone else is in your class? – CaldwellYSR Feb 23 '12 at 06:44
  • yeah i think so but there asking different things. And i can't really understand his code. – user1205958 Feb 23 '12 at 06:50
  • Edited to better answer question. – CaldwellYSR Feb 23 '12 at 07:11