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 2 of 2

Thread: Setting Boolean to 'True' after X amount of Seconds?

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Setting Boolean to 'True' after X amount of Seconds?

    As the title says, are there any simple solutions to make a boolean true after x amount of seconds? Right now, I have it that when the enter key is clicked the boolean will turn true which is ok, but this is for a simple game and the boolean turning true brings an enemy onto the screen, so it's kinda silly if you can control when the enemy will pop up on the screen (since the boolean turning true is done by hitting 'enter').

    Since it only brings on one enemy every time the boolean is true, I"d need for it to be set back to false afterward and then be turned to true after x amount of seconds again. Any ideas are appreciated.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Setting Boolean to 'True' after X amount of Seconds?

    Assuming you are using a gui, you can a) Multi-thread the application and use something like Thread.sleep to pause threads or b) Using a Swing Timer. I would recommend option b for ease of use.

    a) Lesson: Concurrency (The Java™ Tutorials > Essential Classes)
    b) How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)

Similar Threads

  1. [SOLVED] Least Coins Needed For Amount class
    By mwardjava92 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 5th, 2011, 04:36 PM
  2. [SOLVED] isPrime Boolean Method returns true for squares of primes
    By Staticity in forum What's Wrong With My Code?
    Replies: 0
    Last Post: September 29th, 2011, 11:46 PM
  3. I want to extract minutes and seconds from duration
    By msa969 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 17th, 2011, 02:14 PM
  4. Really Quick n00b question, should take three seconds to answer
    By joeschmidt45 in forum Java Theory & Questions
    Replies: 4
    Last Post: February 24th, 2011, 05:23 AM
  5. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM