用java實現2008北京奧運會倒計時

說明:簡單的在 Label上顯示“距2008北京奧運會還有××天”,主要學習Frame和Label的 添加;還有時間的操作。

完整代碼:

import java.awt.*;
import java.util.*;
import java.util.Calendar.*;
public class Welcome2008 {
   public static void main (String[] args){
     Frame f=new Frame("2008奧運會!");
     Calendar xmas = new GregorianCalendar();//get the date of today
     Calendar newyears = new GregorianCalendar(2008,Calendar.AUGUST,8); //2008.8.8
     long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis();//Get difference in ms
     long diffDays = diffMillis/(24*60*60*1000)+1;  //Get difference in days
     Label lab1=new Label("距2008北京奧運會還有"+diffDays+"天");
     f.add(lab1);
     f.setSize(200,100);
     f.setVisible(true);

     }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章