`
rita_ka
  • 浏览: 10926 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

java倒数60s实现

    博客分类:
  • Java
 
阅读更多

 

在JAVA程序中添加一个能倒数的类

 

import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
 
class MyTimer extends TimerTask
{
 
 private Timer timer;
 private int time;
 //JLabel soul;
 //JLabel jj;
 MyTimer()
 {
  
 }
 
 MyTimer(Timer timer,int time)
 {
 // this.jj = jj;
 // this.soul = soul; 
  this.time=time;
  this.timer=timer;
 }
 
 public void run()
 {
 System.out.println(this.time);
//  soul.setText(""+time);
  this.time--;
  
  if(this.time<0)
  {
   //JOptionPane.showMessageDialog(null, "你的最终得分"+jj.getText());
      this.timer.cancel();
  }
 }
}
 
 
 
在主函数添加:
    //倒数60s
    Timer t = new Timer();
     int s=60; 
      MyTimer mt=new MyTimer(t,s);
      t.scheduleAtFixedRate(mt,0,1000);
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics