+ 2

Start and stop buttons

Hi, First I know GUI code don't work on SoloLearn app but anyone who can correct my   code please assist. I have a code below with an example of my question. On my code I have 2 Jbuttons, one is to stop a while loop and the second is to re-start a while loop. I'm able to click the "stop" button to stop a loop but when I click a start button nothing happens. Notice I'm doing this operation on a deferent thread. I also tried the Swing Worker but I encounter the same problem. I read somewhere that I can only use this operation once on a Swing Worker. Anyone know how I can Stop/Start the while loop as I desire on a program or on my code? https://code.sololearn.com/cB929QgJ1oqY/?ref=app https://code.sololearn.com/cB929QgJ1oqY/?ref=app

25th Jan 2019, 6:26 AM
Sibusiso Mbambo
8 Answers
+ 2
Because having a code compiler would take up HEAPS of memory, the code is excecjted on a server. The server sends back only the text output, so it’s not possibke to use graphics in the SoloLean Code Playground.
26th Jan 2019, 4:22 AM
Rowsej
Rowsej - avatar
+ 2
Oh sorry, I read your question wrong. I am not sure how to fix your problem.
26th Jan 2019, 4:27 AM
Rowsej
Rowsej - avatar
+ 2
I would make it so when you press a button, the value of a variable is updated. The other button would change the variable back. In the main loop, if the variable is equal to something (the “off” value), then it would skip that iteration.
26th Jan 2019, 4:31 AM
Rowsej
Rowsej - avatar
+ 2
Abdul Moqueet Code working perfectly, thanks!
28th Jan 2019, 8:40 AM
Sibusiso Mbambo
+ 1
Based on lack of replies, I guess no one has an answer.
26th Jan 2019, 4:23 AM
Sibusiso Mbambo
+ 1
Yes, you answered but not my question based on a code.
26th Jan 2019, 4:25 AM
Sibusiso Mbambo
+ 1
What should I do on my code to make buttons control the while loop continuously?
26th Jan 2019, 4:27 AM
Sibusiso Mbambo
+ 1
Thanks, I will try it when I'm using my laptop at the moment I'm using my phone.
26th Jan 2019, 8:39 AM
Sibusiso Mbambo