Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Problem with running a while loop triggered by a boolean

  1. #1
    nateibar is offline Member
    Join Date
    May 2015
    Posts
    1
    Rep Power
    0

    Question Problem with running a while loop triggered by a boolean

    Hello! I'm trying to make a slot machine using NetBeans (I'm also very new to Java), with a Swing GUI Jframe form. I've got the essence of the game and visuals down, but I'd like for some advanced visuals. I'm trying to get four different text fields, which represent the slots, rapidly switch between different images to give the illusion of the slot machine spinning after the Spin button is pressed.

    Problem with running a while loop triggered by a boolean-capture-design-circle.png

    Here are the slots, circled in red. The slots are represented by letters of a special font, where each image is a letter (the circle is A, the square B, the triangle C, and the diamond D).

    I have the String array slots, String[] slots = {"A", "B", "C", "D"}
    Boolean value Spinning, which is set to true once the button Spin is actionPerformed (and later set to false in the actionPerformed)

    When the Spin button is pushed, I set the boolean Spinning to true, which should prompt a (while) loop (while (Spinning == true)), where each text field is setText to a random value from slots. I'm using Thread.sleep(100) as my waiting period between each iteration of the loop.

    So where do I put this while loop? I can't put it in the actionPerformed of the button, and I can't put it in the main arguments (static argument error), and putting it anywhere else gives me an error.

    Thanks and please let me know if you need any more information!

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Problem with running a while loop triggered by a boolean

    Funny how questions come in batches. Like this person:

    http://www.java-forums.org/new-java/...iteration.html

    you should be looking into using a Swing timer rather than trying to roll your own solution.
    DarrylBurke likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 6
    Last Post: 01-16-2014, 01:48 PM
  2. Infinite loop using boolean as condition
    By midnightcoffee in forum New To Java
    Replies: 2
    Last Post: 11-14-2013, 11:50 PM
  3. Replies: 7
    Last Post: 12-18-2011, 04:13 AM
  4. Limiting loop in boolean string
    By jimmy-lin in forum New To Java
    Replies: 7
    Last Post: 10-10-2009, 06:31 AM
  5. i need assistance with a string triggered loop please!
    By Phobos0001 in forum New To Java
    Replies: 9
    Last Post: 11-14-2007, 02:44 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
  •