/home/wpollock1/public_html/AJava/TimerDemo.java

// Demo for Timers.  This code prints out the current time every 5 seconds
// (and also plays a "beep" sound).  "%Tr" means to format as "hh:mm:ss ?M"
// (?M means either AM or PM).  This continues until the user types
// control+C.
//
// Written 4/2021 by Wayne Pollock, Tampa Florida USA

import java.util.*;
import java.awt.Toolkit;
import java.time.LocalTime;

public class TimerDemo {
    public static void main (String[] args) {
        Timer everyFiveSeconds = new Timer();

        TimerTask task = new TimerTask() {
            @Override
            public void run () {
                System.out.printf("At the tone, the time will be %Tr%n",
                    LocalTime.now() );
                Toolkit.getDefaultToolkit().beep();
            }
        };

        everyFiveSeconds.scheduleAtFixedRate( task, 0, 5_000 );
    }
}