成都网站建设设计

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

倒计时1分钟java代码的简单介绍

关于JAVA里的倒计时代码

我试了一下没有错呀!

成都地区优秀IDC服务器托管提供商(创新互联).为客户提供专业的资阳托管服务器,四川各地服务器托管,资阳托管服务器、多线服务器托管.托管咨询专线:13518219792

我还有一个:

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编写一个倒计时器代码。

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的程序?求具体步骤!

基于控制台的话很简单的,我跟你说一下大体思路吧,二话不说先来个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("爆炸");

}

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


网页标题:倒计时1分钟java代码的简单介绍
文章出自:http://chengdu.cdxwcx.cn/article/hdssjg.html