⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timecountdown.java

📁 简单的奥运倒计时牌子
💻 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 + -