当前位置: 代码迷 >> Java相关 >> 定时器中,定义的任务是每十秒弹出一个窗口,窗口停留3秒后自动消失
  详细解决方案

定时器中,定义的任务是每十秒弹出一个窗口,窗口停留3秒后自动消失

热度:186   发布时间:2016-04-22 21:32:45.0
定时器中,定义的任务是每10秒弹出一个窗口,窗口停留3秒后自动消失。
代码如下:

 package kankan;                          
 import java.util.*;                      
 import javax.swing.*;                    
import java.awt.event.*;                  
import java.awt.*;                        
import javax.swing.Timer;                 
//判断是否在线                            
public class CloseWindowIn5 extends JFrame{                                                  
private JButton button=new JButton("签到")                          
public void  window(){                                                            
 this.setSize(300, 400);                  
 this.setLocation(40, 50);                
 this.setVisible(true);                   
 setLayout(null);                         
 button.setBounds(110,180,70,70);         
 add(button);                             
 button.addActionListener(new ActionListen
  public void actionPerformed(ActionEvent 
  System.out.println(“在线”);                               
  }                                       
});                                       
 }                                                                                   
public void run() {                       
try {                                     
Thread.sleep(5000);                       
 this.dispose();                          
} catch (InterruptedException e) {        
e.printStackTrace();                      
}                                                                                  
}                                                                                  
  相关解决方案