사용자가 작업 이름, 시간 및 날짜와 같은 정보를 입력하는 스케줄러 응용 프로그램에서 작업하고 있습니다. 응용 프로그램은 현재 시간에 작업이 있으면 매분마다 확인해야하며 창을 팝업하거나 소리를냅니다. 이제 나는 확인 과정에 박혀있다.캘린더 클래스를 사용하는 스케줄러
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();
}
}
프레임 업을 팝업하지 않는 경우 현재 시간 = 작업의 텍스트 파일의 시간, 그래서 누군가가이 코드 조각으로 무엇이 잘못되었는지 말해 것입니다!
미리 감사드립니다. :)
여기서 currTask [2]는 텍스트 파일의 분 필드이고 이고 currTask [3]은 텍스트 파일의 시간 필드입니다. –
** 당신이 ** 무엇이 잘못되었는지 우리에게 말하면 ** 더 나은 해결책이 될 것입니다 ** – SJuan76
이것을 손으로 완전히 할 이유가 있습니까? cron4j와 같은 것을 사용 하는게 어떨까요? – greedybuddha