I have a written a java code to popup a dialog box every day at 8pm (20:00 hours). However the code worked for the first time only and didn't work later after I changed the time. This is my code:
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JOptionPane;
public class PopUp {
public static void main(String[] args) {
Timer timer = new Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);
if (hour == 20 && min == 00 && sec == 0) {
JOptionPane.showMessageDialog(null, "PopUp Success at "+new Date().toString());
System.out.println("PopUp Success at "+new Date().toString());
}
}
};
timer.schedule(tt, 1000, 1000 * 5);
}
}
Is there anything wrong with my code? Plz help me out in solving this issue to popup the dialog box every day at 8pm.