I am new to JAVA. After reviewing a few examples - I wrote the semblance of a stopwatch using Timer. After executing the program, 500 minutes of the stopwatch pass in 2 to 3 seconds. Apparently somewhere something messed up with syntax. I would be grateful for the help. Also I will accept any suggestions for optimizing this code.
import java.util.Timer; import java.util.TimerTask; public class ut extends TimerTask { Timer timer; public void run(){ int seconds = 0, minutes = 0; while (true) { seconds++; if (minutes != 0) System.out.print(minutes + ":"); System.out.println(seconds); if (seconds == 59) { seconds = -1; minutes++; } if (minutes == 500){ timer.cancel(); } } } public static void main(String[] args) { new Timer().schedule(new ut(), 10); } }
I also read that you can somehow implement this task through the swing. If anyone knows how to implement it and whether it will be easier than this example, I will be grateful for the help.