import java.util.*; import java.awt.*; public class TimerClient extends Frame implements AlarmEventListener { protected AlarmTimer timer; //------------------------------------------------------------------- // main() entry point //------------------------------------------------------------------- public static void main (String[] args) { new TimerClient(); } //------------------------------------------------------------------- // TimerClient Constructor //------------------------------------------------------------------- public TimerClient() { super("Timer Demo Window"); // create a timer timer = new AlarmTimer(40); // 40 seconds timer.setTickInterval(5); // initial ticks every 5 seconds timer.setFont( new Font("Courier", Font.BOLD, 22)); // set display font try { timer.addAlarmStoppedEventListener(this); timer.addAlarmTickedEventListener(this); } catch (TooManyListenersException ex) { System.out.println("Could not register: " + ex); } add(timer, "Center"); // center spot of BorderLayout setSize(new Dimension(200,200)); // 1.0 resize() setVisible(true); // 1.0 show() timer.start(); System.out.println("X-33 Launch countdown started.."); } //------------------------------------------------------------------- // AlarmEventListener interface methods //------------------------------------------------------------------- public void alarmTicked(AlarmEvent tick) { int time; time = tick.getSeconds(); System.out.println("T minus " + time + " seconds..and counting."); // when timer hits the 10-seconds-left point, speed up ticks to // one per second. if ( timer.getTickInterval() == 5 && time < 15 ) { timer.setTickInterval(1); // change display font for last 10 seconds timer.setFont( new Font("TimesRoman", Font.ITALIC, 32)); } } public void alarmStopped( AlarmEvent timeOut) { System.out.println("Houston, we have lift-off !!"); System.exit(0); } } // End of Class TimerClient