2012-07-09 51 views
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);它给了我一个错误,无法访问的代码。

+3

你在哪里添加它? – 2012-07-09 17:53:34

+0

你想在哪里停止这 – 2012-07-09 17:53:36

+0

你在哪里添加Thread.sleep()调用? – 2012-07-09 17:53:46

回答

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){ 

        } 


      } 
+0

表示感谢! – jerhynsoen 2012-07-09 18:24:33

+0

你是最受欢迎的 – 2012-07-09 18:25:32

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){} 
}