class Timer extends Thread { int counter = 0, showFor; public Timer(int showFor) { this.showFor = showFor; } public void run() { while (counter <= showFor) { try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } counter++; } } }