真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java時鐘倒計時代碼 java時鐘倒計時代碼大全

怎么編寫一個倒計時的java的程序?求具體步驟!

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

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供江山網(wǎng)站建設、江山做網(wǎng)站、江山網(wǎng)站設計、江山網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、江山企業(yè)網(wǎng)站模板建站服務,10年江山做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。

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)頁的還是基于用戶界面都可以使用這個思路的

java 倒計時

//搞定,代碼自己理解哈.

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("時間到!");

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("倒計時");

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("開始倒計時");

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 // 運行秒針線程

{

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() {

/*

* 顯示倒計時

*/

l.setText(this.LabelTime);

}

}

}

}

用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 設計一個簡單的倒計時

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.util.Timer;

import java.util.TimerTask;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class TimeThreadFrame extends JFrame{

// 定義組件

private JLabel lblTime;

private JTextField txtInput;

private JButton btnEnter;

// 構造方法

public TimeThreadFrame(){

// 設置窗體的相關屬性

super("TimerThread");

this.setSize(300,200);

this.setLayout(null);

this.setLocation(100,50);

// 創(chuàng)建組件

this.lblTime = new JLabel("請輸入倒計時時間");

this.lblTime.setBounds(30,20,200,30);

this.txtInput = new JTextField();

this.txtInput.setBounds(30,70,100,30);

this.btnEnter = new JButton("確定");

this.btnEnter.setBounds(150,70,70,30);

// 給JTextField注冊監(jiān)聽

this.txtInput.addKeyListener(new KeyListener(){

public void keyPressed(KeyEvent ke) {

}

public void keyReleased(KeyEvent ke) {

}

public void keyTyped(KeyEvent ke) {

txtInput_KeyTyped(ke);

}

});

// 給JButton注冊監(jiān)聽

this.btnEnter.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){

btnEnter_ActionPerformed(ae);

}

});

// 將各組件添加到窗體上

add(lblTime);

add(txtInput);

add(btnEnter);

// 顯示窗體

this.setVisible(true);

}

// 輸入時的事件處理,控制用戶只能輸入數(shù)字

public void txtInput_KeyTyped(KeyEvent ke){

if(ke.getKeyChar() '0' || ke.getKeyChar() '9'){

ke.setKeyChar('\0');

}

}

// 點擊按鈕時的事件處理,核心!

public void btnEnter_ActionPerformed(ActionEvent ae){

// 獲得用戶輸入的倒計時時間

String strTime = this.txtInput.getText();

if(strTime.equals("")){

// 檢測用戶是否輸入

this.lblTime.setText("您尚未輸入,請輸入!");

}

else{

Integer time = Integer.parseInt(strTime);

// 創(chuàng)建線程

TimeThread tt = new TimeThread(this.lblTime,time);

tt.start();

// 創(chuàng)建Timer

Timer timer = new Timer();

timer.schedule(new TimerTask(){

// 啟動其他程序

public void run() {

System.out.print("ok");

}

}, time * 1000);

}

}

// 啟動窗體

public static void main(String[] args){

new TimeThreadFrame();

}

}

// 時間線程類

class TimeThread extends Thread{

private JLabel lblTime;

private int time;

// 構造方法傳入,顯示事件的JLabel和倒計時的時間。

public TimeThread(JLabel lblTime, int time){

this.lblTime = lblTime;

this.time = time;

}

// run方法

public void run(){

while(time 0){

// 顯示所剩時間

this.lblTime.setText("所剩時間:" + time);

// 所剩時間減少

time--;

try {

this.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

java Timer倒數(shù)計時器(急)

哎這個太簡單了。。。

Timer t = new Timer();

int s = 5;

TimerTask tt = new TimerTask()

{

public void run()

{

if(s 0)

s--;

}

};

t.scheduleAtFixedRate(tt,0,1000);

怎樣用JAVA寫一個10鐘倒計時程序?

import java.awt.Color;

import java.util.*;

import java.awt.*;

import java.applet.*;

public class Clock extends Applet implements Runnable

{

Thread timer=null;

Label label;

int lastxs=50,lastys=30,lastxm=50,lastym=30,lastxh=50,lastyh=30;

public void init()

{

label=new Label(" ");

setBackground(Color.white);

add(label);

}

public void paint(Graphics g)

{

int xh,yh,xm,ym,xs,ys,s,m,h,xcenter,ycenter;

Date rightnow=new Date();

String today=rightnow.toLocaleString();

label.setText(today);

s=rightnow.getSeconds();

m=rightnow.getMinutes();

h=rightnow.getHours();

xcenter=100;

ycenter=80;

xs=(int)(Math.cos(s*3.14f/30-3.14f/2)*45+xcenter);

ys=(int)(Math.sin(s*3.14f/30-3.14f/2)*45+ycenter);

xm=(int)(Math.cos(m*3.14f/30-3.14f/2)*45+xcenter);

ym=(int)(Math.sin(m*3.14f/30-3.14f/2)*45+ycenter);

xh=(int)(Math.cos((h*30+m*2)*3.14f/180-3.14f/2)*30+xcenter);

yh=(int)(Math.sin((h*30+m*2)*3.14f/180-3.14f/2)*30+ycenter);

g.setFont(new Font("TimesToman",Font.PLAIN,14));

g.setColor(Color.orange);

g.fill3DRect(xcenter-50,ycenter-50,100,100,true);

g.setColor(Color.darkGray);

g.drawString("12",xcenter-5,ycenter-37);

g.drawString("3",xcenter+40,ycenter+3);

g.drawString("6",xcenter-3,ycenter+45);

g.drawString("9",xcenter-45,ycenter+3);

g.setColor(Color.orange);

if(xs!=lastxs||ys!=lastys)

{

g.drawLine(xcenter,ycenter,lastxs,lastys);

}

if(xm!=lastxm||ym!=lastym)

{

g.drawLine(xcenter,ycenter-1,lastxm,lastym);

g.drawLine(xcenter-1,ycenter,lastxm,lastym);

}

if(xh!=lastxh||yh!=lastyh)

{

g.drawLine(xcenter,ycenter-1,lastxh,lastyh);

g.drawLine(xcenter-1,ycenter,lastxh,lastyh);

}

g.setColor(Color.red);

g.drawLine(xcenter,ycenter,xs,ys);

g.drawLine(xcenter,ycenter-1,xm,ym);

g.drawLine(xcenter-1,ycenter,xm,ym);

g.drawLine(xcenter,ycenter-1,xh,yh);

g.drawLine(xcenter-1,ycenter,xh,yh);

lastxs=xs;

lastys=ys;

lastxm=xm;

lastym=ym;

lastxh=xh;

lastyh=yh;

}

public void start()

{

if(timer==null)

{

timer=new Thread(this);

timer.start();

}

}

public void stop()

{

timer=null;

}

public void run()

{

while(timer!=null)

{

try

{

Thread.sleep(1000);

}catch(InterruptedException ie){}

repaint();

}

timer=null;

}

public void update(Graphics g)

{

paint(g);

}

}


分享名稱:java時鐘倒計時代碼 java時鐘倒計時代碼大全
本文來源:http://weahome.cn/article/hpigdh.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部