RE: Introduction to Loops with Java 08-14-2016, 08:56 AM
#3
(08-14-2016, 08:48 AM)BxxxxxD~~ Wrote: would you be able to help me with an issue I'm having with a loop in java?
The problem is that I want a button to be able to start an infinite loop, and then end the loop when the button is repressed.
But, because it is a loop that loops constantly, the program will freeze and the user will be unable to press the button again once it has been started.
The second part of the issues is that the button needs to be pressed again to stop the loop, however whenever the button is pressed the loop will start.
If you can help that would be great, but either way your tutorial is well layed out and pretty helpful.
Hey, Threads aren't in the scope of this ttutorial but the reason your GUI freezes is because you aren't using a separate Thread. Since a single thread runs the Java GUI, the infinite loop won't allow it to render the button. Hence create another Thread, put the while loop inside it.. Try it and then report back



![[+]](https://sinister.li/images/modern/collapse_collapsed.png)