我正在开发一个调度程序应用程序,用户在其中输入一些信息,如任务名称、时间和日期。如果当前时间有任务,应用程序应该每分钟检查一次,它会弹出一个窗口或发出声音。现在我坚持检查过程。
public static void main(String[] args) {
try{
final BufferedReader br = new BufferedReader(new FileReader("D://Courses//PlannerText.txt"));
final Runnable checker = new Runnable() {
public void run() {
Calendar cal = Calendar.getInstance();
System.out.println( "This is time before if statement "+cal.get(Calendar.HOUR) +":" + cal.get(Calendar.MINUTE) );
try {
String line = null;
while ( (line = br.readLine()) !=null)
{
String[] currTask = line.split("\\|");
if (cal.get(Calendar.MINUTE)== Integer.parseInt(currTask[2])
&& cal.get(Calendar.HOUR) == Integer.parseInt(currTask[3])){
System.out.println( "This is time after if statement "+cal.get(Calendar.HOUR) +":" + cal.get(Calendar.MINUTE) );
System.out.println("This is the time of the task "+currTask[3]+":"+currTask[2]);
JFrame reminderFrame = new JFrame("Reminder");
reminderFrame.setVisible(true);
reminderFrame.setLocation(200,200);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
final ScheduledFuture checkerHandle = scheduler.scheduleAtFixedRate(checker, 0, 1, TimeUnit.MINUTES);
scheduler.schedule(new Runnable() {
public void run() {
checkerHandle.cancel(true);
}
}, 1, TimeUnit.DAYS);
}catch(FileNotFoundException e){
e.printStackTrace();
}
}
当前时间=文本文件中任务的时间时,框架不会弹出,所以有人能告诉我这段代码有什么问题吗!
提前致谢 :)