Hi,
I've written a timer that is pretty simple and uses a thread to increment seconds, then sleep(1000), to wait 1 seconds then loop again and increment a seconds again. This thread just runs in a while loop. I use a System.out.println to print out the result each time the loop runs through a cycle.
I've written a GUI using Swing for it so there's a start, pause and reset button which all works fine. So I now have a Timer class and a Gui class. However the time is displayed on the system prompt screen, not in the GUI. I wanted to display it in a text box so I can see it count upwards in the GUI.
I tried a while loop that runs in the start buttons action listener method, and it simply takes the result from a method in the timer class over and over and displays it so it does work! HOWEVER, while the loop is running the Start button remains locked down, and none of the other buttons can be pressed, and the window won't close, so I have to terminate it from the system prompt!
Is there any way that I can display the result in a text box so it's only updated when the thread increments a second? I'm sure there must be a simple way around this but I haven't figured it out yet!
I've written a timer that is pretty simple and uses a thread to increment seconds, then sleep(1000), to wait 1 seconds then loop again and increment a seconds again. This thread just runs in a while loop. I use a System.out.println to print out the result each time the loop runs through a cycle.
I've written a GUI using Swing for it so there's a start, pause and reset button which all works fine. So I now have a Timer class and a Gui class. However the time is displayed on the system prompt screen, not in the GUI. I wanted to display it in a text box so I can see it count upwards in the GUI.
I tried a while loop that runs in the start buttons action listener method, and it simply takes the result from a method in the timer class over and over and displays it so it does work! HOWEVER, while the loop is running the Start button remains locked down, and none of the other buttons can be pressed, and the window won't close, so I have to terminate it from the system prompt!
Is there any way that I can display the result in a text box so it's only updated when the thread increments a second? I'm sure there must be a simple way around this but I haven't figured it out yet!