...

View Full Version : Timed Loop



cowbell1
02-28-2008, 08:41 PM
Hi.
I am currently working on a program where you imput a number (Zero or One) and you hit a button printing out a line(Motor 1 is pushed). My teacher wants me to make a timed loop that runs for 2 seconds then prints "Both motors are moving forward."

The problem is I have no knowledge of timed loops! I know how to do a loop in java, but as far as having the loop hold for 2 seconds then print something is beyond me. How do I go about doing this?

Aradon
02-28-2008, 10:01 PM
You have two options, you can either make a timertask or you can just sleep the thread until you want to print it.

An example of thread.sleep can be seen here:

Thread (http://java.sun.com/docs/books/tutorial/essential/concurrency/sleep.html)

That's my suggestion that you do (since you're just starting out in java).

But if you want to read up!

TimerTask (http://www.onjava.com/pub/a/onjava/2004/03/10/quartz.html)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum