Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Timed Loop

  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Timed Loop

    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?

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    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

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

    But if you want to read up!

    TimerTask
    "To iterate is human, to recurse divine." -L. Peter Deutsch


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •