java年份倒計(jì)時(shí)代碼,javaweb倒計(jì)時(shí)

關(guān)于JAVA里的倒計(jì)時(shí)代碼

我試了一下沒有錯(cuò)呀!

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的惠民網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

我還有一個(gè):

script LANGUAGE="JavaScript"

!--你可以將新年改為其它的節(jié)日--

var urodz= new Date("January 29,2006");

var s="新年";

var now = new Date();

var ile = urodz.getTime() - now.getTime();

var dni = Math.floor(ile / (1000 * 60 * 60 * 24));

if (dni 1)

document.write("今天離"+s+"還有"+dni +"天")

else if (dni == 1)

document.write("只有2天啦!")

else if (dni == 0)

document.write("只有1天啦!")

else

document.write("好象已經(jīng)過了哦!");

/script

用java編寫一個(gè)倒計(jì)時(shí)器代碼。

import java.awt.BorderLayout;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class TimerDemo extends JFrame implements ActionListener { private static final long serialVersionUID = 201306211111L; private JTextField screen = new JTextField("0"); private JButton start = new JButton("開始"); private JButton reset = new JButton("重置"); private JPanel panel = new JPanel(); private boolean isRunning; private int time; private int timeBetween; public TimerDemo(int timeBetween) { super("計(jì)時(shí)器"); this.timeBetween = timeBetween; try { init(); } catch (Exception e) { e.printStackTrace(); } } public TimerDemo() { super("計(jì)時(shí)器"); this.timeBetween = 100; try { init(); } catch (Exception e) { e.printStackTrace(); } } private void init() { panel.setLayout(new GridLayout()); panel.add(start); panel.add(reset); start.addActionListener(this); reset.addActionListener(this); screen.setFont(new Font("幼圓", Font.BOLD, 60)); screen.setHorizontalAlignment(JTextField.CENTER); screen.setEditable(false); Container c = getContentPane(); c.setLayout(new BorderLayout()); c.add(panel, BorderLayout.SOUTH); c.add(screen, BorderLayout.CENTER); this.setSize(200, 150); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setLocationRelativeTo(null); this.setVisible(true); } public static void main(String[] args) { new TimerDemo(1);// 設(shè)定 1ms/次 // new TimerDemo(); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == start) { if (start.getText().equals("開始")) { start.setText("暫停"); isRunning = true; } else if (start.getText().equals("暫停")) { start.setText("開始"); isRunning = false; } } if (e.getSource() == reset) { start.setText("開始"); screen.setText("0"); isRunning = false; time = 0; } new Thread(new TimeZone()).start(); } class TimeZone implements Runnable { @Override public void run() { while (isRunning) { time++; if (time = Integer.MAX_VALUE) { screen.setText("ERROR"); JOptionPane.showMessageDialog(null, "ERROR"); isRunning = false; } screen.setText(String.valueOf(time)); try { Thread.sleep(timeBetween); } catch (Exception e) { e.printStackTrace(); } } } }}

用java遍寫元旦倒計(jì)時(shí)

import?java.util.Calendar;

import?java.util.Date;

public?class?Countdown2?implements?Runnable?{

public?static?void?main(String[]?args)?{

Thread?cd?=?new?Thread(new?Countdown2());

cd.start();

}

@Override

public?void?run()?{

//?設(shè)置日期2012-12-21

Calendar?c?=?Calendar.getInstance();

c.set(2016,?1,?1,?0,?0,?0);

//?單獨(dú)設(shè)置年、月、日、小時(shí)、分鐘、秒

c.set(Calendar.YEAR,?2015);

c.set(Calendar.MONTH,?Calendar.DECEMBER);?//?0?表示1月,11?表示12月

c.set(Calendar.DAY_OF_MONTH,?21);

c.set(Calendar.HOUR_OF_DAY,?0);

c.set(Calendar.MINUTE,?0);

c.set(Calendar.SECOND,?0);

//?獲取2012-12-21?0:0:0時(shí)間點(diǎn)對應(yīng)的毫秒數(shù)

long?endTime?=?c.getTimeInMillis();

//?獲取系統(tǒng)當(dāng)前時(shí)間

Date?now?=?new?Date();

//?獲取當(dāng)前時(shí)間點(diǎn)對應(yīng)的毫秒數(shù)

long?currentTime?=?now.getTime();

//?計(jì)算兩個(gè)時(shí)間點(diǎn)相差的秒數(shù)

long?seconds?=?(endTime?-?currentTime)?/?1000;

while?(true)?{

long?days?=?seconds?/?(3600?*?24);

long?h?=?seconds?%?(3600?*?24)?/?3600;

long?m?=?seconds?%?(3600?*?24)?%?3600?/?60;

long?s?=?seconds?%?(3600?*?24)?%?3600?%?60;

System.out.println("離2016年元旦還剩:?"?+?days?+?"天"?+?h?+?"小時(shí)"?+?m?+?"分"?+?s?+?"秒");

seconds--;

try?{

Thread.sleep(1000);

}?catch?(InterruptedException?e)?{

e.printStackTrace();

}

}

}

}

怎么編寫一個(gè)倒計(jì)時(shí)的java的程序?求具體步驟!

基于控制臺的話很簡單的,我跟你說一下大體思路吧,二話不說先來個(gè)for循環(huán),然后輸出倒計(jì)時(shí)的數(shù)字,程序睡一秒,在輸出倒計(jì)時(shí)數(shù)字,如此循環(huán),簡單吧,下面看程序:

public static void main(String[] args) {

for(int i=10;i0;i--){

System.out.print(i+" ");

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

System.err.print("爆炸");

}

其他基于網(wǎng)頁的還是基于用戶界面都可以使用這個(gè)思路的

當(dāng)前題目:java年份倒計(jì)時(shí)代碼,javaweb倒計(jì)時(shí)
標(biāo)題鏈接:http://www.muchs.cn/article10/hssgdo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、用戶體驗(yàn)移動網(wǎng)站建設(shè)、網(wǎng)站制作搜索引擎優(yōu)化、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名