import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.JOptionPane;
public class ReminderService {
Timer timer = new Timer();
class Item extends TimerTask {
String message;
Item(String m) {
message = m;
}
public void run() {
message(message);
}
}
public static void main(String[] argv) throws IOException {
new ReminderService().load();
}
protected void load() throws IOException {
SimpleDateFormat formatter =new SimpleDateFormat ("yyyy MM dd hh mm");
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy MM dd hh mm");
//设置提醒时间和提醒内容
String aLine="2021 05 01 21 14 时间提醒成功";
ParsePosition pp = new ParsePosition(0);
Date date = formatter.parse(aLine, pp);
if (date == null) {
message("Invalid date in " + aLine);
}
String mesg = aLine.substring(pp.getIndex());
timer.schedule(new Item(mesg), date);
}
void message(String message) {
System.out.println("\007" + message);
JOptionPane.showMessageDialog(null,message,"Timer Alert",
JOptionPane.INFORMATION_MESSAGE);
}
}