} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
〖求救】关于一个倒计时的Java代码 。。。head
script language="JavaScript"
var timedate=new Date(2007,0,1);
var times="元旦";
var now=new Date();
var date=timedate.getTime()-now.getTime();
var time=Math.floor(date/(1000*60*60*24));
if(time=0)
document.write("现在离"+times+"还有:"+time+"天");
/script
/head
body/body
/html
。。
怎么编写一个倒计时的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();}@Overridepublic 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 {@Overridepublic 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代码和css元旦倒计时代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 移动硬盘怎么保存空间视频,移动硬盘怎么存档
- 怎么查找陌生人的视频号,怎么查找陌生人的视频号点赞记录
- 虚拟机游戏老重启黑屏,虚拟机玩游戏黑屏
- thinkphpword转html的简单介绍
- vb.net生成条形码 c# 生成条形码
- jquery模糊搜索定位,jq模糊选择器
- linux命令退出u盘 linux退出系统命令
- js数组用n分隔,js数组分组
- 荣耀8a如何升级鸿蒙系统,荣耀8a升级鸿蒙系统怎么升级