Countdown Timer In Java Using Threading
This is a simple Countdown program in Java which is done using threading. In this program the console is periodically cleared with a Console Object. The Basic design is to make the thread sleep for 1 sec till the give time is reached. The hours and Mins along with seconds are at first converted to seconds and a loop does the rest of the work ! Screenshot [Demo] The Code: import java.io.Console; import java.util.Scanner; public class timer { public static final char ESC = 27; public static void main(String as[])throws Exception { Scanner s=new Scanner(System.in); String tim; int hh,mm=0,ss=0; int sec; Console c = System.console(); if (c == null) { System.err.println("no console"); System.exit(1); } System.out.println("Enter In this format: \"HH:MM:SS\""); tim=s.next(); hh=Integer.parseInt(tim.substring(0,2)); mm=Integer.parseInt(tim.substring(3,5)); ss=Integer.parseInt(tim.substring(6,8)); sec=hh*3600+mm*60+ss; ...