This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I have a program with 3 buttons, namely start/stop/step. I have a loop which moves a circle around on a JPanel. I want the loop to be started when the user presses "start" and the loop to "stop" when the user presses stop (the program has to remember the current state of the loop). When the users presses start again the loop has to start where it left of. When the user presses "step" the loop has to make one step in the loop (step will only be possible when the loop is stopped). What is the easiest way to do this? Do I need to threat my program to listen to the buttons while my loop is running?
Yes, you basically would have a thread running that animates the circle. (You might want to use a Timer or something.)
The Buttons would change the state of a model, which the timer uses to determine what exactly it should do.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus