java - How would i stop my timer? -
So I created a timer class for the game vs. and I already have the start button action to start the timer, But I'm confused how to stop the timer and reset it back to 0. If someone can provide some solution to my problem then it would be nice.
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 (); }}} edit OK, I have a stop button that needs to be done completely, but reset A trouble in the button
Any suggestions?
P>
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 (); }}}}
Call it method .. restart it and Stop () to stop it.
Comments
Post a Comment