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: Looping until keypress. How is this done?

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

    Angry Looping until keypress. How is this done?

    Let me give context.

    I'm writing a program that uses JFugue, and I want it to loop a particular pattern over and over again until the user presses a key on the keyboard (anyone not familiar with JFugue: play a tune over and over again).

    Now, I'm using keylisteners like a good programmer, now, the problem is how can I tell the loop to keep going until a keyevent is received by the listener? I've been looking for an answer pretty well everyone and haven't found anything close to this dilemma. I'm getting many "take input until someone types 'quit'" kind of problems, which I know how to code, but that isn't what I am looking for. The program isn't waiting for input before doing something, its doing something until it receives input.

    Any ideas?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Looping until keypress. How is this done?

    how can I tell the loop to keep going until a keyevent is received by the listener?
    Have the loop test a boolean variable and exit the loop when its value changes. Your loop should be careful to not use the GUI's thread.
    Use a key listener or keybinding to set the boolean variable when the key is pressed.

Similar Threads

  1. Looping an inputstream
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 02:39 PM
  2. Help in looping
    By endframe in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 28th, 2010, 03:24 PM
  3. Looping with an ArrayList
    By EmSaint in forum Loops & Control Statements
    Replies: 3
    Last Post: September 23rd, 2010, 12:06 AM
  4. Keypress simulation problems
    By ummix in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 6th, 2010, 07:31 AM
  5. [SOLVED] looping, for,while,do-while.
    By chronoz13 in forum Loops & Control Statements
    Replies: 4
    Last Post: August 6th, 2009, 01:32 PM