Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Line to Cursor
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DemonWasp




PostPosted: Fri Mar 18, 2011 9:17 am   Post subject: RE:Line to Cursor

The documentation for the Java API is here: http://download.oracle.com/javase/6/docs/api/

The function you want to use is Thread.sleep(milliseconds): http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html#sleep(long)

You will have to put the call to Thread.sleep() in a try-catch block as it can throw an exception (you can probably ignore any exception it throws).
Sponsor
Sponsor
Sponsor
sponsor
secondgear




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
apython1992




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 24 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: