Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: how to set timer

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    68
    My Mood
    Cool
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default how to set timer

    Hi ,

    i want to set a timer for 6 seconds ,and once that timer expires i need to do a particular operation ..
    how can i achieve this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: how to set timer

    Which timer are you going to use? There are two. The recommended one is javax.swing.Timer.
    Read the class's API doc. It has an example.
    Or go to: The Really Big Index
    and search for Timer

  3. #3
    Member
    Join Date
    Jun 2011
    Posts
    68
    My Mood
    Cool
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: how to set timer

    Norm
    i dont need swing timer..
    I am looking to run a system clock type timer in a thread and once elapsed it sets a flag which is read in another thread.
    any easy solution /commands??

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: how to set timer

    You can get the system time from a method in the System class.

    None of the timers I know of set a flag. They call a method when the time expires. It is up to the programmer to write code to do what he wants to do when the time expires.

Similar Threads

  1. How to Use Timer in Java
    By neo_2010 in forum Java SE API Tutorials
    Replies: 2
    Last Post: August 6th, 2013, 09:49 AM
  2. Ticked Off Timer
    By JavaCow in forum Loops & Control Statements
    Replies: 8
    Last Post: October 30th, 2010, 09:18 AM
  3. Timer Class help
    By Deadbob in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 22nd, 2010, 11:18 PM
  4. need help with Timer and sound
    By amahara in forum AWT / Java Swing
    Replies: 4
    Last Post: February 18th, 2010, 11:22 AM
  5. Timer?
    By TimW in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 27th, 2009, 07:43 AM