成都网站建设设计

将想法与焦点和您一起共享

java倒计时代码并转换,java 倒计时器

关于JAVA里的倒计时代码

我试了一下没有错呀!

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、网站空间、营销软件、网站建设、柞水网站维护、网站推广。

我还有一个:

script LANGUAGE="JavaScript"

!--你可以将新年改为其它的节日--

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("好象已经过了哦!");

/script

java 就一个100 的倒计时代码 代码简单点

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("结束");

}

怎么编写一个倒计时的java的程序?求具体步骤!

基于控制台的话很简单的,我跟你说一下大体思路吧,二话不说先来个for循环,然后输出倒计时的数字,程序睡一秒,在输出倒计时数字,如此循环,简单吧,下面看程序:

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("爆炸");

}

其他基于网页的还是基于用户界面都可以使用这个思路的

用java编写一个倒计时器代码。

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("计时器"); this.timeBetween = timeBetween; try { init(); } catch (Exception e) { e.printStackTrace(); } } public TimerDemo() { super("计时器"); 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);// 设定 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中30秒倒计时(转换成string返回到Label控件的text)

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;

JButton jButton2;

JLabel jLabel1;

int i =30;

Thread th = new Thread(this);

volatile boolean threadDone = true;

public void run()

{

while (threadDone) {

for (; i =0threadDone; i--) {

jLabel1.setText(i+"");

try {

Thread.sleep(1000);

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

public TimerText()

{

jButton1 = new JButton("停止");

jButton2 = new JButton("继续");

jLabel1 = new JLabel();

jLabel1.setText(i+"");

this.add(jLabel1);

th.start();

jButton1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

threadDone = false;

}

});

jButton2.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if(!threadDone){

threadDone = true;

new Thread(TimerText.this).start();

}

}

});

this.add(jButton1);

this.add(jButton2);

this.setLayout(new FlowLayout());

this.setBounds(200, 100, 200, 80);

this.setVisible(true);

}

public static void main(String[] args)

{

new TimerText();

}

}


当前文章:java倒计时代码并转换,java 倒计时器
本文地址:http://chengdu.cdxwcx.cn/article/hsjecd.html