?? timecountdown.java
字號:
/**
* <p>Title:TimeCountDown</p>
* <p>Discription:自己的程序,提供倒計時秒數和現在時間</p>
* @author DELL
* @version 1.0
*/
package Project1;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.*;
public class TimeCountDown extends JPanel implements Runnable{
//之后再試驗下在這個位置定義全局變量
Thread clocker = new Thread();
JLabel now = new JLabel();
JLabel left = new JLabel();
public int CountDay(){
int day = 0;
Calendar rightnow = Calendar.getInstance();
int year = rightnow.get(Calendar.YEAR);
if (year<2008){
day = (2008 - year)*365 - rightnow.get(Calendar.DAY_OF_YEAR) +220;
}else{
day = 220 - rightnow.get(Calendar.DAY_OF_YEAR);
}
return day;
}
public long CountSeconds(){
long seconds = 0;
Calendar rightnow = Calendar.getInstance();
int day = CountDay();
seconds = (day+1)*86400
- rightnow.get(Calendar.HOUR_OF_DAY)*3600
- rightnow.get(Calendar.MINUTE)*60
- rightnow.get(Calendar.SECOND);
return seconds;
}
public void run(){
while (true) {
Date nw = new Date();
SimpleDateFormat time = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss aaa");
now.setText(time.format(nw));
left.setText(new Long(CountSeconds()).toString());
try {
clocker.sleep(1000);
}
catch (InterruptedException ie) {
System.err.print(ie);
}
}
}
public static void main(String[] args){
TimeCountDown time = new TimeCountDown();
System.out.println(time.CountDay());
System.out.println(time.CountSeconds());
time.run();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -