Results 1 to 2 of 2
  1. #1
    MaJellin is offline Member
    Join Date
    Mar 2010
    Rep Power

    Default Setting a variable to false with a keybinding to terminate a while loop by pressing


    I'm trying to use a spacebar keybinding to set a variable to "false" so that I can pass that variable into the while loop and then while the loop is running (its a long loop) I can hit the spacebar, turn the variable to false and stop the loop.

    How can I do this?


  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    The loop has to be running in a thread.

    The Object must have a instance boolean that the loop monitors; declare it volatile so that all threads see the same value.

    Keybinding is done in AWT/Swing. See the tutorial.

Similar Threads

  1. Setting the environment variable for j2sdk
    By kiki2009 in forum Java Servlet
    Replies: 3
    Last Post: 07-04-2009, 06:14 AM
  2. Using string to terminate loop
    By mrblippy in forum New To Java
    Replies: 3
    Last Post: 04-23-2009, 07:16 AM
  3. Setting a variable in JSTL for use in a JSP function
    By MikeStringfellow in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-19-2009, 05:48 PM
  4. Variable not initialized after while loop
    By ejs7597 in forum New To Java
    Replies: 6
    Last Post: 02-28-2009, 06:00 AM
  5. [SOLVED] Referencing Variable within Loop
    By Judoon_Platoon in forum Java Applets
    Replies: 2
    Last Post: 05-22-2008, 12:54 PM

Posting Permissions

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