FileDocCategorySizeDatePackage
ReminderService.javaAPI DocExample1863Sat Nov 25 12:54:52 GMT 2000None

ReminderService

public class ReminderService extends Object
Read a file of reminders, sleep until each is due, beep.
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: ReminderService.java,v 1.3 2000/11/25 17:54:52 ian Exp $

Fields Summary
ArrayList
l
Constructors Summary
Methods Summary
protected voidload()


		BufferedReader is = new BufferedReader(
			new FileReader("ReminderService.txt"));
		SimpleDateFormat formatter =
			new SimpleDateFormat ("yyyy MM dd hh mm");
		String aLine;
		while ((aLine = is.readLine()) != null) {
			ParsePosition pp = new ParsePosition(0);
			Date date = formatter.parse(aLine, pp);
			if (date == null) {
				message("Invalid date in " + aLine);
				continue;
			}
			String mesg = aLine.substring(pp.getIndex());
			l.add(new Item(date, mesg));
		}
	
public static voidmain(java.lang.String[] argv)


	       
		ReminderService rs = new ReminderService();
		rs.load();
		rs.run();
	
voidmessage(java.lang.String message)

		System.out.println("\007" + message);
		JOptionPane.showMessageDialog(null,
			message, 
			"Timer Alert",				// titlebar
			JOptionPane.INFORMATION_MESSAGE);	// icon
	
public voidrun()

		System.out.println("ReminderService: Starting at " + new Date());
		while (!l.isEmpty()) {
			Date d = new Date();
			Item i = (Item)l.get(0);
			long interval = i.due.getTime() - d.getTime();
			if (interval > 0) {
				System.out.println("Sleeping until " + i.due);
				try {
					Thread.sleep(interval);
				} catch (InterruptedException e) {
					System.exit(1);	// unexpected intr
				}
				message(i.due + ": " + i.message);
			} else
				message("MISSED " + i.message + " at " + i.due);
			l.remove(0);
		}
		System.exit(0);