我试了一下没有错呀!
我还有一个:
script LANGUAGE="JavaScript"
!--你可以将新年改为其它的节日--
var s="新年";
var now = new Date();
var ile = urodz.getTime() - now.getTime();
if (dni 1)
document.write("今天离"+s+"还有"+dni +"天")
else if (dni == 1)
else if (dni == 0)
document.write("只有1天啦!")
else
document.write("好象已经过了哦!");
/script
public?static?void?main(String[]?args)?{
for?(int?i?=?100?;?i?=?0?;?i?--)?{
System.out.println(i);
try?{
Thread.sleep(1000);
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
System.out.println("结束");
基于控制台的话很简单的,我跟你说一下大体思路吧,二话不说先来个for循环,然后输出倒计时的数字,程序睡一秒,在输出倒计时数字,如此循环,简单吧,下面看程序:
public static void main(String[] args) {
for(int i=10;i0;i--){
System.out.print(i+" ");
try {
} catch (InterruptedException e) {
System.err.print("爆炸");
其他基于网页的还是基于用户界面都可以使用这个思路的
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
public class TimerText extends JFrame implements Runnable {
JButton jButton1;
JLabel jLabel1;
Thread th = new Thread(this);
volatile boolean threadDone = true;
public void run()
{
while (threadDone) {
for (; i =0threadDone; i--) {
jLabel1.setText(i+"");
} catch (Exception e) {
public TimerText()
jButton1 = new JButton("停止");
jLabel1 = new JLabel();
this.add(jLabel1);
th.start();
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
threadDone = false;
});
if(!threadDone){
threadDone = true;
new Thread(TimerText.this).start();
this.add(jButton1);
this.setLayout(new FlowLayout());
this.setVisible(true);
public static void main(String[] args)
new TimerText();
以上就是土嘎嘎小编为大家整理的java倒计时代码并转换相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!