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

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

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

寫一個(gè)計(jì)時(shí)器 JAVA代碼是什么?

應(yīng)該用線程里面的Timer來控制package com.sy.game.test;

創(chuàng)新互聯(lián)公司專注于息烽網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供息烽營(yíng)銷型網(wǎng)站建設(shè),息烽網(wǎng)站制作、息烽網(wǎng)頁設(shè)計(jì)、息烽網(wǎng)站官網(wǎng)定制、微信小程序定制開發(fā)服務(wù),打造息烽網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供息烽網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。

import java.util.Timer;

import java.util.TimerTask;

public class TimeTask {

public static void main(String[] args) {

TimeTask tTask=new TimeTask();

tTask.timeVoid();

}

public void timeVoid(){

final Timer timer = new Timer();

TimerTask tt=new TimerTask() {

@Override

public void run() {

System.out.println("到點(diǎn)啦!");

timer.cancel();

}

};

timer.schedule(tt, 3000);

}

}

整合的:

/*

* java倒計(jì)時(shí)器

* shiyang

* */

package com.sy.game.test;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.Timer;

@SuppressWarnings("unused")

public class TimeController extends JFrame implements ActionListener {

private static final long serialVersionUID = 4603262282860990473L;

private static final int DEFAULT_WIDTH = 200;

private static final int DEFAULT_HEIGHT = 100;

private static final int width = Toolkit.getDefaultToolkit()

.getScreenSize().width;

private static final int height = Toolkit.getDefaultToolkit()

.getScreenSize().height;

private Container container;

private JButton btn;

private JTextField jtfTime;

private Timer tmr;

public TimeController() {

initComponents();

Timer tmr = new Timer(1000, this);

this.tmr = tmr;

setVisible(true);

}

private void initComponents() {

this.setTitle("SY秒表");

this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

this.setResizable(false);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLocation((width - DEFAULT_WIDTH) / 2,

(height - DEFAULT_HEIGHT) / 2);

jtfTime = new JTextField("10");

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

container = getContentPane();

JPanel panel = new JPanel();

panel.add(btn);

panel.add(jtfTime);

this.add(panel);

btn.addActionListener(this);

}

public void actionPerformed(ActionEvent ae) {

if (ae.getSource() == btn) {

jtfTime.setText("10");

tmr.start();

} else {

int t;

t = Integer.parseInt(jtfTime.getText());

t--;

jtfTime.setText("" + t);

if (t = 0) {

tmr.stop();

}

}

}

public static void main(String[] args) {

TimeController timeController = new TimeController();

}

}

用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實(shí)現(xiàn)一個(gè)計(jì)時(shí)器?

用java實(shí)現(xiàn)一個(gè)計(jì)時(shí)器的方法:

publicclassTestDingShiimplementsRunnable

{

Threadxc;

Daodao=newDaoImpl();

publicTestDingShi()

{

xc=newThread(this);//線程開啟

xc.start();

}

publicvoidrun()

{

while(true)

{

try

{

xc.sleep(1000);//睡眠開始計(jì)時(shí)

}

catch(InterruptedExceptione)

{

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

//TODO定時(shí)在此

}

}

}


新聞名稱:計(jì)時(shí)器的java代碼 java 倒計(jì)時(shí)器
文章轉(zhuǎn)載:http://weahome.cn/article/hgciij.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部