0

我无法让它入睡,我希望它在继续之前暂停一秒钟。

public static void main(String[] args) {  
        //supply your own path instead of using this one 
        String path = "\\image.JPG";  
        for(;;)
            SPI.INSTANCE.SystemParametersInfo(     
                new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),    
                new UINT_PTR(0),      
                path,          
                new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));
        }

当我尝试添加 Thread.sleep(1000); 它给了我一个错误,无法访问的代码。

4

2 回答 2

1

确保您将添加sleep()到 for 循环的内部,而不是外部。

你还需要抓住潜力InterruptedException

for(;;)
    SPI.INSTANCE.SystemParametersInfo(     
        new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),    
        new UINT_PTR(0),      
        path,          
        new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));

    try {
        Thread.sleep(1000l);
    } catch(InterruptedException e){}
}
于 2012-07-09T17:54:11.100 回答
1

试试这个......在 for 循环中添加 sleep 方法。

public static void main(String[] args) {  
        //supply your own path instead of using this one 
        String path = "\\image.JPG"; 

        for(;;){

                try{
                    Thread.sleep(1000);
                    SPI.INSTANCE.SystemParametersInfo(     
                    new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),    
                    new UINT_PTR(0),      
                    path,          
                    new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));
                    }catch(Exception ex){

                    }


          }
于 2012-07-09T17:56:47.710 回答