欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

倒數(shù)計(jì)時(shí)java代碼,java倒計(jì)時(shí)三種簡單實(shí)現(xiàn)方式

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

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

站在用戶的角度思考問題,與客戶深入溝通,找到舒城網(wǎng)站設(shè)計(jì)與舒城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請(qǐng)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋舒城地區(qū)。

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è)思路的

用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.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

public class Clock extends JFrame

{

private Dialog dialog;

public static void main(String[] args)

{

Clock f = new Clock();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

}

class MyDialog extends Dialog implements WindowListener,ActionListener

{

JLabel label;

JPanel panel1,panel2;

JButton button;

public MyDialog(Frame owner, String title, boolean modal) {

super(owner, title, modal);

// TODO Auto-generated constructor stub

label=new JLabel("時(shí)間到!");

button=new JButton("確定");

panel1=new JPanel();

panel2=new JPanel();

panel1.setLayout(new BorderLayout());

panel1.add("Center",label);

panel2.add("Center",button);

this.add("Center",panel1);

this.add("South",panel2);

this.setSize(200,200);

this.setResizable(false);

this.addWindowListener(this);

button.addActionListener(this);

}

public void windowOpened(WindowEvent e) {

// TODO Auto-generated method stub

}

public void windowClosing(WindowEvent e) {

// TODO Auto-generated method stub

this.setVisible(false);

}

public void windowClosed(WindowEvent e) {

// TODO Auto-generated method stub

}

public void windowIconified(WindowEvent e) {

// TODO Auto-generated method stub

}

public void windowDeiconified(WindowEvent e) {

// TODO Auto-generated method stub

}

public void windowActivated(WindowEvent e) {

// TODO Auto-generated method stub

}

public void windowDeactivated(WindowEvent e) {

// TODO Auto-generated method stub

}

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

this.setVisible(false);

}

}

Clock()

{

setTitle("倒計(jì)時(shí)");

setSize(320, 120);

dialog=new MyDialog(this,"提示:",true);

ClockPanel p = new ClockPanel();

add(p);

}

class ClockPanel extends JPanel

{

private JButton b;

private boolean onetime = true;;

private JLabel lfen, lmiao, l;

private JTextField tf, tm;

ClockPanel() {

b = new JButton("開始倒計(jì)時(shí)");

lfen = new JLabel("分");

lmiao = new JLabel("秒");

l = new JLabel("00:00");

tf = new JTextField(3);

tm = new JTextField(3);

l.setFont(new Font("宋體", Font.BOLD, 30));

l.setForeground(Color.RED);

b.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

if (onetime) {

if (tf.getText().trim().equals("")) {

tf.setText("00");

}

if (tm.getText().trim().equals("")) {

tm.setText("00");

}

new ChangeLabel(tf.getText().trim() + ":"

+ tm.getText().trim()).start();

}

}

});

add(tf);

add(lfen);

add(tm);

add(lmiao);

add(b);

add(l);

}

class ChangeLabel extends Thread // 運(yùn)行秒針線程

{

private int minitues;

private String Sminitues;

private int sound;

private String Ssound;

private String LabelTime;

public ChangeLabel(String time) {

// TODO Auto-generated constructor stub

onetime = false;

this.minitues = Integer.parseInt(time.substring(0, time

.indexOf(':')));

this.sound = Integer

.parseInt(time.substring(time.indexOf(':') + 1));

}

private long time1;

private long time2;

public void run() {

time1 = System.currentTimeMillis();

while (true) {

time2 = System.currentTimeMillis();

while (!(minitues == 0 sound == 0) time2 = time1 + 1000) {

time1 = time2;

if (sound == 0) {

sound = 59;

minitues--;

} else {

sound--;

}

LabelTime = this.getTime();

display();

}

if (minitues == 0 sound == 0) {

dialog.setVisible(true);

onetime = true;

break;

}

}

}

private String getTime() {

if (minitues 10)

this.Sminitues = "0" + minitues;

else

this.Sminitues = "" + minitues;

if (sound 10)

this.Ssound = "0" + sound;

else

this.Ssound = "" + sound;

return this.Sminitues + ":" + this.Ssound;

}

public void display() {

/*

* 顯示倒計(jì)時(shí)

*/

l.setText(this.LabelTime);

}

}

}

}

分享標(biāo)題:倒數(shù)計(jì)時(shí)java代碼,java倒計(jì)時(shí)三種簡單實(shí)現(xiàn)方式
網(wǎng)頁路徑:http://chinadenli.net/article34/dsieipe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、外貿(mào)網(wǎng)站建設(shè)、建站公司網(wǎng)站內(nèi)鏈、ChatGPT關(guān)鍵詞優(yōu)化

廣告

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

成都網(wǎng)站建設(shè)公司