java - Restarting a method with ActionListener -


I'm making a timer for a game vs., but IM has hard times in my timer method's restart Have given. It stops the timer for one second, then the counting continues, Example: If the timer is on 4, if the reset button is killed, the timer will pause 4 for the second, then again for 5, 6, etc. Will start. Still to fix it?

  import javax.swing. *; Import java.awt. *; Import java.awt.event. *; The expansion of public class MyTimer panel (private Jeelab time display; private Jebtn Risetbtn; private Jebtn Startbtn; private Jebtn Stopbutn; Timer; public MyTimer () {MyTimer timer; Startbutton = new Jebtn ( "Start Timer"); Stopbtn = new Jebtn ( "stop timer"); Taimdisple = new Jeelabel ( "... waiting ..."); Risetbtn = new Jebtn ( "reset timer"); this.add (resetButton); this.add (StartButton); this.add (stopButton); this.add (timeDisplay); Event E = new event (); StartButton.addActionListener (e); Event 1C = new Event 1 (); stopButton.addActionListener (c); Event 2D = new Event 2 (); resetButton.addActionListener (d);} public class event implementation ActionListener {public void action functional (ActionEvent e) {int count = 0; TimeDisplay.setText ( "time has passed time:" + count); Taimclas TC = new Taimclas (calculated); timer = new timer (1000, TC) ; Timer.start ();}} public class TimeClass ActionListener applied {int counter; public timecounter} {this.counter = counter; } Public Numerology (ActionEvent e) {Counter ++; TimeDisplay.setText ("Time Elapsed Time:" + Counter); }} Class event1 implementation ActionListener {public zero action action (action avenue) {timer.stop (); }} Class Event 2 Action Alicer applies {public Zero Action Perffered (Action Event D) {Timer. Retert (); }}}}    

A global counter in the MyTimer class Create Stable Volatile Int Counter; .... Class Event implement the ActionListener {public void Action (ActionEvent e) handle {// condition that start button is clicked / Once more frequent consistently if (timer == NULL) {Taimclas TC = New timeclass (); Timer = new timer (1000, TC); } Timer.start (); }} TimeClass implementation of ActionListener {execution of Public Zero Action (ActionEvent e) {Counter ++; TimeDisplay.setText ("Time Elapsed Time:" + Counter); }} Class event1 implements execution {public void action if the handle {// condition functional (ActionEvent c) stop is clicked before starting the timer (timer! = NULL) {timer.stop (); }}}}}}}} Event2 executes ActionListener {Public Zero Action Functional (ActionEvent D) {// Counter Counter = 0 Reset; // handle the situation if the reset is clicked before starting the timer (timer! = Null) {timer.restart (); }}}

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -