0

我正在开发一个调度程序应用程序,用户在其中输入一些信息,如任务名称、时间和日期。如果当前时间有任务,应用程序应该每分钟检查一次,它会弹出一个窗口或发出声音。现在我坚持检查过程。

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();
    }
}

当前时间=文本文件中任务的时间时,框架不会弹出,所以有人能告诉我这段代码有什么问题吗!

提前致谢 :)

4

2 回答 2

0

欢迎来到调试概念。放置一些调试断点或打印输出以显示 currTask 数组的值。

可能您使用了错误的数组索引或时间错误(可能是 HOUR_OF_DAY)

于 2013-05-17T02:50:28.847 回答
0

谢谢大家,但我已经弄清楚了......因为我的缓冲阅读器在我的 run() 方法之外,所以文件在启动时只被读取一次,而不是每分钟读取一次。

于 2013-05-17T11:09:42.313 回答