我正在开发一个警报应用程序。我正在使用 SwingUtilities.invokeLater 方法来调用我的 UI 以实现贪睡功能。但是当我运行它时,我注意到 SwingUtilities.invokeLater 函数没有被调用。请帮我解决这个问题
public class IsTime {
int hrs;
int min;
int sec;
GregorianCalendar clk=new GregorianCalendar();
Calendar gtl= Calendar.getInstance();
mp3 mix=new mp3();
public void makeReady(int h,int m,int s,String ampm){
Calendar c1=Calendar.getInstance();
c1.set(Calendar.HOUR_OF_DAY,h);
c1.set(Calendar.MINUTE, m);
c1.set(Calendar.SECOND,s);
if("PM".equals(ampm)){
c1.set(Calendar.AM_PM, Calendar.PM);
if(Calendar.getInstance().get(Calendar.AM_PM)==Calendar.PM){
if(c1.after(Calendar.getInstance())){
check(c1);
}
c1.set(Calendar.DAY_OF_YEAR,c1.get(Calendar.DAY_OF_YEAR)+1);
check(c1);
}
}
if(Calendar.getInstance().get(Calendar.AM_PM)==Calendar.AM){
if(c1.after(Calendar.getInstance())){
check(c1);
}
c1.set(Calendar.DAY_OF_YEAR,c1.get(Calendar.DAY_OF_YEAR)+1);
check(c1);
}
if(Calendar.getInstance().get(Calendar.AM_PM)==Calendar.PM){
c1.set(Calendar.DAY_OF_YEAR,c1.get(Calendar.DAY_OF_YEAR)+1);
check(c1);
}
}
public void check(Calendar ch){
while(!(Calendar.getInstance().after(ch))){//this line checks if it is time to sound alarm
}
SwingUtilities.invokeLater(new Runnable(){//here is my invokelater method
public void run(){
System.out.println("git to invoke");
new Snooze();
}
});
mix.start();
}
public void makeReady(int mis){
Calendar sz=Calendar.getInstance();
sz.set(Calendar.SECOND, 0);
sz.set(Calendar.MINUTE, Calendar.getInstance().get(Calendar.MINUTE)+mis);
check(sz);
}
}