If you want to do the stopwatch using only Timer class then you will need to decide when and how you start it. The textbook starts it immediately but you need to read the textbox and convert the content to an integer variable (say named "count").
The timer cannot be started inside the actionPerformed method since it will work only once but have to be set in some external method so that once started it will call actionPerformed every time it changes to do the updates of the graphics values and manage the count by decrementing it.
Then if you create such external method like:
public void start() { if (count!=0) timer.start( ); }
then inside actionPerformed you need to have two conditions checked:
1. if ( src == “your button” ) then get the text, convert it into an integer count and issue:
start(); ( see the method above)
2. if ( src == timer ) , meaning that timer value has changed since it has been started AFTER the previous condition has been processed, then do the operations on count by decrementing it and updating values necessary for graphics.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment