Author |
Message |
DemonWasp
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
secondgear
|
Posted: Fri Mar 18, 2011 9:33 pm Post subject: Re: Line to Cursor |
|
|
so umm this should work?
code: |
int fromX[]= new int[1];
fromX[0]=getCurrentMouseX();
int fromY[]= new int[1];
fromY[0]=getCurrentMouseY();
try {
Thread.sleep(5000);
} catch(InterruptedException e) {
}
int toX[]= new int[1];
toX[0]=getCurrentMouseX();
int toY[]= new int[1];
toY[0]=getCurrentMouseY();
g.drawLine(fromX[0], fromY[0], toX[0], toY[0]);
|
|
|
|
|
|
 |
Insectoid

|
Posted: Fri Mar 18, 2011 9:42 pm Post subject: RE:Line to Cursor |
|
|
Nope. fromX[] will need to be as big as the number of points you want. At the moment, fromX[] is acting just like an integer. |
|
|
|
|
 |
secondgear
|
Posted: Fri Mar 18, 2011 9:45 pm Post subject: Re: Line to Cursor |
|
|
I don't understand that.
fromX is the mouseX to draw a line you need fromMouseX and fromMouseY to the other X and other Y, Can you explain what I am doing wrong pleas?E |
|
|
|
|
 |
DemonWasp
|
Posted: Sat Mar 19, 2011 2:50 am Post subject: RE:Line to Cursor |
|
|
You've got the basic idea correct -- you will need to draw a line from the last point stored in the fromX and fromY arrays to the new point. However, you're still missing two big pieces of this puzzle.
First, you need to store at least several more entries in these arrays -- probably at least a history of the last 10-20 positions, if not more. You will also need to connect them with lines.
Second, you need to implement adding the "new" coordinates to the array. |
|
|
|
|
 |
secondgear
|
Posted: Sat Mar 19, 2011 10:41 am Post subject: Re: Line to Cursor |
|
|
I understand I need more points otherwise it will just be a straight line. But I want it to be following the cursor movement. I also need it to remove the last points as the cursor moves further or after a few seconds. I have no idea how to do that. Can someone just do it for me -__-?? |
|
|
|
|
 |
apython1992

|
Posted: Sat Mar 19, 2011 12:31 pm Post subject: RE:Line to Cursor |
|
|
But if someone does it for you, you won't learn anything! Just keep trying to figure out what you have to do, and if you don't know how to do it, you can always look it up. For example, if you think you need to remove the last points as the cursor moves further, look up how to remove elements from an array in Java. To start, I suggest looking at Java's ArrayList, instead of just a regular array. |
|
|
|
|
 |
secondgear
|
Posted: Sat Mar 19, 2011 12:39 pm Post subject: Re: Line to Cursor |
|
|
Well if I look at code I'll know how to do it in the future... |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
apython1992

|
Posted: Sat Mar 19, 2011 12:54 pm Post subject: Re: Line to Cursor |
|
|
secondgear @ Sat Mar 19, 2011 12:39 pm wrote: Well if I look at code I'll know how to do it in the future... I'm not so sure about that. There's something to be said about thinking clearly and logically about a solution to a problem, as opposed to just blindly staring at code and wondering how it works.
The skills you'll develop from learning how to actually think about solutions far outweigh anything you'll gain from memorizing someone else's solution. |
|
|
|
|
 |
|