中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

java的倒計(jì)時(shí)代碼 java 倒計(jì)時(shí)器

java 就一個(gè)100 的倒計(jì)時(shí)代碼 代碼簡(jiǎn)單點(diǎn)

public?static?void?main(String[]?args)?{

安慶網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、響應(yīng)式網(wǎng)站開(kāi)發(fā)等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。成都創(chuàng)新互聯(lián)從2013年創(chuàng)立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專(zhuān)注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。

for?(int?i?=?100?;?i?=?0?;?i?--)?{

System.out.println(i);

try?{

Thread.sleep(1000);

}?catch?(InterruptedException?e)?{

e.printStackTrace();

}

}

System.out.println("結(jié)束");

}

怎么在頁(yè)面顯示5分鐘的倒計(jì)時(shí) 用java代碼

給你一個(gè)javascript 5秒 倒計(jì)時(shí)的例子。

title無(wú)標(biāo)題文檔/title

script type="text/javascript"

var totalTime=parseInt(6);

function countDown(){

if(totalTime==0){

return;

}else{

totalTime=totalTime-1;

window.document.form1.timeText.value=totalTime;

setTimeout("countDown()",1000);

}

}

/script

/head

body

form name="form1"

input type="text" name="timeText" /

input type="button" value="start" onclick="countDown();"

/form

/body

/html

如果用java實(shí)現(xiàn)web 倒計(jì)時(shí),那么就一種后果,不斷的刷新頁(yè)面。除非用ajax 或者 javascript 還有一個(gè)就是 applet。 有啥問(wèn)題可以hi我交流

java 毫秒倒計(jì)時(shí)器 想編寫(xiě)一個(gè)方法,其中就有一個(gè)參數(shù) 倒計(jì)時(shí)多長(zhǎng)時(shí)間

import java.awt.BorderLayout;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.SwingConstants;

public class NanoTimeframe extends JPanel

{

private static final long serialVersionUID = -6135068834705503622L;

private JLabel lblTime;

private long start = 0L; // 從0毫秒開(kāi)始

private static long MAXTIME = 5000L; // 5秒后結(jié)束

private boolean begin = false;

private JTextField setTime;

public NanoTimeframe()

{

this.lblTime = new JLabel("單擊開(kāi)始");

this.setTime = new JTextField();

System.out.println("1");

this.lblTime.setFont(new Font("Monospaced", Font.BOLD, 60));

this.lblTime.setHorizontalAlignment(SwingConstants.CENTER);

this.lblTime.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e)

{

MAXTIME = Long.parseLong(setTime.getText());

begin = true;

lblTime.setText(timeStr(start));

}

});

setLayout(new BorderLayout());

add(lblTime, BorderLayout.CENTER);

add(setTime, BorderLayout.NORTH);

}

private String timeStr(long time)

{

StringBuffer timeBuffer = new StringBuffer();

long miu = time / (60 * 1000);

time -= miu * 60 * 1000;

long se = time / 1000;

time -= se * 1000;

long mi = time % 1000;

timeBuffer.append(miu 10 ? ("0" + miu) : miu);

timeBuffer.append(".");

timeBuffer.append(se 10 ? ("0" + se) : se);

timeBuffer.append(".");

timeBuffer.append(mi 10 ? ("00" + mi) : (mi 100 ? ("0" + mi) : mi));

return timeBuffer.toString();

}

@Override

public void paintComponent(Graphics page)

{

if (!begin) return;

super.paintComponent(page);

if (start = MAXTIME)

{

lblTime.setText("Bomb!!!");

return;

}

start += 1;

lblTime.setText(timeStr(start));

}

public static void main(String [] args){

JFrame jf = new JFrame();

jf.setResizable(false);

jf.setBounds(0, 0, 460, 330);

jf.setLocationRelativeTo(null);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jf.add(new NanoTimeframe());

jf.setVisible(true);

}

}

請(qǐng)給分 改得辛苦上面輸入毫秒后計(jì)時(shí)

用java編一個(gè)簡(jiǎn)單的倒計(jì)時(shí)表

先不要關(guān)閉問(wèn)題,給我點(diǎn)時(shí)間我編出來(lái),我也想斷煉一下。

代碼如下:

我這程序有點(diǎn)問(wèn)題 ,這倒計(jì)時(shí)你講的功能都有了,但那個(gè)暫停按鈕有問(wèn)題,只能用兩次,我怎么也找不出原因, 我想是多線(xiàn)程方面的問(wèn)題吧,按兩下那暫停按鈕就失去作用了。

--------------------------MainFrame.java------------------------------------

import java.awt.Button;

import java.awt.FlowLayout;

import java.awt.Frame;

import java.awt.Label;

import java.awt.TextField;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

public class MainFrame extends Frame{

Dispose dp= null;

int flag=1; //暫停開(kāi)始的按鈕,1為計(jì)時(shí)中,0為暫停。

Button button=null;

Label l1 =null;

Label l2 =null;

Label l3 = null;

TextField tfh =null;

TextField tfm =null;

TextField tfs =null;

public void lanchFrame(){

this.setLocation(200,200);

this.setSize(200,200);

this.setLayout(new FlowLayout());

l1=new Label("hour");

tfh = new TextField("1",6);

l2=new Label("minute");

tfm = new TextField("3",6);

l3=new Label("second");

tfs = new TextField("5",6);

button = new Button("stop");

this.add(l1);

this.add(tfh);

this.add(l2);

this.add(tfm);

this.add(l3);

this.add(tfs);

this.add(button);

button.addActionListener(new StartAndStopListener(this));

this.addWindowListener(new MyClosingListener());

this.dp = new Dispose(this);

this.pack();

this.setVisible(true);

}

public static void main(String args[]){

MainFrame mf=new MainFrame();

mf.lanchFrame();

mf.dp.run(mf);

}

private class MyClosingListener extends WindowAdapter{

public void windowClosing(WindowEvent e){

System.exit(0);

}

}

}

--------------------------Dispose.java------------------------------------

public class Dispose {

int hour;

int minute;

int second;

public Dispose(MainFrame mf) {

this.hour = Integer.parseInt(mf.tfh.getText());

this.minute = Integer.parseInt(mf.tfm.getText());

this.second = Integer.parseInt(mf.tfs.getText());

}

public void run(MainFrame mf) {

while (!(hour == 0 minute == 0 second == 0) mf.flag == 1) {

if (second == 0) {

if (minute 0) {

second = 59;

minute--;

}

}

if (minute == 0) {

if (hour 0) {

minute = 59;

hour--;

}

}

second--;

mf.tfs.setText(second + "");

mf.tfm.setText(minute + "");

mf.tfh.setText(hour + "");

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

------------------------------StarAndStopListener.java-----------------------------

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class StartAndStopListener implements ActionListener {

MainFrame mf = null;

public StartAndStopListener(MainFrame mf){

this.mf = mf;

}

public void actionPerformed(ActionEvent arg0) {

if(mf.flag==0){

mf.flag =1;

mf.button.setLabel("stop");

mf.dp.run(mf);

}

if(mf.flag == 1){

mf.flag = 0;

mf.button.setLabel("start");

}

}

}

誰(shuí)有用java的application編寫(xiě)的倒計(jì)時(shí)鐘代碼?

package hello;

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

import java.util.*;

import java.awt.geom.*;

public class T extends Applet implements Runnable{

Thread tHour = null,tMinute = null,tSecond = null;//表示時(shí)針,分針和秒針的線(xiàn)程

int hour_a,hour_b,minute_a,minute_b,second_a,second_b;//表示時(shí)針,分針,秒針端點(diǎn)的整型變量

int hour = 0,minute = 0,second = 0;//獲取當(dāng)前時(shí)間的整型變量

//繪制時(shí)針,分針和秒針的Graphics對(duì)象

Graphics g_second = null,g_minute = null,g_hour =null;

//存放表盤(pán)刻度的數(shù)組,供指針走動(dòng)時(shí)使用

double point_x[] = new double[61],point_y[] = new double[61];

//存放表盤(pán)刻度的數(shù)組,供繪制表盤(pán)使用

double scaled_x[] = new double[61],scaled_y[] = new double[61];

//判斷小程序是否重新開(kāi)始的變量

int start_count = 0;

public void init(){

g_hour = this.getGraphics();

g_hour.setColor(Color.CYAN);

g_second = this.getGraphics();

g_second.setColor(Color.RED);

g_minute = this.getGraphics();

g_minute.setColor(Color.blue);

g_second.translate(200,200);//進(jìn)行坐標(biāo)系統(tǒng)變換,將新坐標(biāo)系原點(diǎn)設(shè)在(200,200)處

g_minute.translate(200,200);

g_hour.translate(200,200);

point_x[0] = 0; point_y[0] = -120;//各個(gè)時(shí)針12點(diǎn)處的位置坐標(biāo)(按新坐標(biāo)系的坐標(biāo))

scaled_x[0] = 0;scaled_y[0] = -140;//12點(diǎn)處的刻度位置坐標(biāo)(按新坐標(biāo)系的坐標(biāo))

double jiaodu = 6*Math.PI/180;

//表盤(pán)分割成60分,將分割點(diǎn)的坐標(biāo)存放在數(shù)組中

for(int i = 0; i 60; i++){

point_x[i+1] = point_x[i]*Math.cos(jiaodu)-Math.sin(jiaodu)*point_y[i];

point_y[i+1] = point_y[i]*Math.cos(jiaodu) + point_x[i]*Math.sin(jiaodu);

}

point_x[60] = 0; point_y[60] = -120;

for(int i = 0; i 60; i++){

scaled_x[i+1] = scaled_x[i]*Math.cos(jiaodu)-Math.sin(jiaodu)*scaled_y[i];

scaled_y[i+1] = scaled_y[i]*Math.cos(jiaodu) + Math.sin(jiaodu)*scaled_x[i];

}

scaled_x[60]= 0;

scaled_y[60] = -140;

}

public void start(){

//每當(dāng)小程序重新開(kāi)始時(shí),首先消滅線(xiàn)程,然后重新開(kāi)始創(chuàng)建線(xiàn)程

if(start_count = 1){

tSecond.interrupt();

tMinute.interrupt();

tHour.interrupt();

}

tSecond = new Thread(this);

tMinute = new Thread(this);

tHour = new Thread(this);

tSecond.start();

tMinute.start();

tHour.start();

start_count++;

if(start_count = 2) start_count = 1;

}

public void stop()

{

tSecond.interrupt();

tMinute.interrupt();

tHour.interrupt();

}

public void paint(Graphics g){

this.start();

g.drawOval(50,50,300,300);//表盤(pán)的外圈

g.translate(200,200);

//繪制表盤(pán)的小刻度和大刻度

for(int i = 0 ; i 60; i++){

if(i%5 == 0){

g.setColor(Color.BLACK);

g.fillOval((int) scaled_x[i],(int) scaled_y[i],10,10);

}

else

g.fillOval((int)scaled_x[i],(int)scaled_y[i],5,5);

}

}

public void run(){

//獲取本地時(shí)間

Date date = new Date();

String s=date.toString();

hour=Integer.parseInt(s.substring(11,13));

minute = Integer.parseInt(s.substring(14,16));

second = Integer.parseInt(s.substring(17,19));

if(Thread.currentThread() == tSecond){

second_a =(int)point_x[second];

second_b = (int)point_x[second];

g_second.drawLine(0,0,second_a,second_b);//秒針的初始位置

g_second.drawString("秒",second_a,second_b);

int i = second;

while(true){

try{

tSecond.sleep(1000);

Color c = getBackground();

g_second.setColor(c);

g_second.drawLine(0,0,second_a,second_b);//用背景色清除前一秒時(shí)的秒針

g_second.drawString("秒",second_a,second_b);

//如果秒針與分針重合,恢復(fù)分針的顯示

if((second_a == minute_a)(second_b == minute_b)){

g_minute.drawLine(0,0,minute_a,minute_b);

g_minute.drawString("分",minute_a,minute_b);

}

//如果秒針與時(shí)針重合,恢復(fù)時(shí)針的顯示

if((second_a == hour_a)(second_b == hour_b)){

g_hour.drawLine(0,0,hour_a,hour_b);

g_hour.drawString("時(shí)",hour_a,hour_b);

}

}

catch(InterruptedException e){

Color c = getBackground();

g_second.setColor(c);

g_second.drawLine(0,0,second_a,second_b);//用背景色清除秒針

g_second.drawString("秒",second_a,second_b);

return;

}

//秒針向前走一個(gè)單位

second_a=(int)point_x[(i+1)%60];

second_b = (int)point_y[(i+1)%60]; //每一秒走6度(一個(gè)單位格)

g_second.setColor(Color.red);

g_second.drawLine(0,0,second_a,second_b);

g_second.drawString("秒",second_a,second_b);

i++;

}

}

if(Thread.currentThread() == tMinute){

minute_a = (int)point_x[minute];

minute_b = (int)point_y[minute];

g_minute.drawLine(0,0,minute_a,minute_b);

int i = minute;

while(true){

//第一次過(guò)60-second秒就前進(jìn)一分鐘,以后每過(guò)60秒前進(jìn)一分鐘

try{

tMinute.sleep(1000*60 - second*1000);

second = 0;

Color c = getBackground();

g_minute.setColor(c);

g_minute.drawLine(0,0,minute_a,minute_b);

g_minute.drawString("分",minute_a,minute_b);

if((hour_a == minute_a)(hour_b== minute_b)){

g_hour.drawLine(0,0,minute_a,minute_b);

g_hour.drawString("時(shí)",hour_a,hour_b);

}

}

catch(InterruptedException e){

return;

}

minute_a = (int)point_x[(i+1)%60];

minute_b = (int)point_y[(i+1)%60];

g_minute.setColor(Color.BLUE);

g_minute.drawLine(0,0,minute_a,minute_b);

g_minute.drawString("分",minute_a,minute_b);

i++; second = 0;

}

}

if(Thread.currentThread() == tHour){

int h = hour%12;

hour_a = (int)point_x[h*5 + minute/12];

hour_b = (int)point_y[h*5 + minute/12];

int i = h*5 + minute/12;

g_hour.drawLine(0,0,hour_a,hour_b);

g_hour.drawString("時(shí)",hour_a,hour_b);

while(true){

//第一次過(guò)12-minute%12分鐘就前進(jìn)一個(gè)刻度,以后每過(guò)12分鐘前進(jìn)一個(gè)刻度

try{

tHour.sleep(1000*60*12 - 1000*60*(minute%12) - second *1000);

minute = 0;

Color c = getBackground();

g_hour.setColor(c);

g_hour.drawLine(0,0,hour_a,hour_b);

g_hour.drawString("時(shí)",hour_a,hour_b);

}

catch(InterruptedException e){

return;

}

hour_a = (int)point_x[(i+1)%60];

hour_b = (int)point_y[(i+1)%60];

g_hour.setColor(Color.CYAN);

g_hour.drawLine(0,0,hour_a,hour_b);

g_hour.drawString("時(shí)",hour_a,hour_b);

i++;minute = 0;

}

}

}

}

新聞名稱(chēng):java的倒計(jì)時(shí)代碼 java 倒計(jì)時(shí)器
網(wǎng)頁(yè)網(wǎng)址:http://m.rwnh.cn/article12/doohdgc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、搜索引擎優(yōu)化自適應(yīng)網(wǎng)站、網(wǎng)站排名、微信小程序、ChatGPT

廣告

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

營(yíng)銷(xiāo)型網(wǎng)站建設(shè)
绥化市| 衡水市| 闵行区| 彭山县| 哈尔滨市| 中方县| 桐城市| 贡觉县| 宁波市| 大新县| 阜平县| 集安市| 南岸区| 沧源| 曲阜市| 碌曲县| 江山市| 台湾省| 丹阳市| 论坛| 平乐县| 宜宾市| 康平县| 吉水县| 班玛县| 当阳市| 尚志市| 博湖县| 色达县| 新干县| 秭归县| 黄骅市| 彭泽县| 揭西县| 磐石市| 迁安市| 锡林郭勒盟| 阿拉善盟| 黄陵县| 晴隆县| 富平县|