當前位置:首頁 » 課程大全 » java課程設計秒錶

java課程設計秒錶

發布時間: 2021-01-31 17:14:10

⑴ JAVA秒錶問題!

16.程序計時版
long time1=System.currentTimeMillis();
long time2=System.currentTimeMillis();
long interval=time2-time1;

17.延時權
try {
Thread.sleep(Integer.Parse(%%1));
} catch(InterruptException e) {
e.printStackTrace();
}

⑵ 怎麼用JAVA 實現秒錶功能 給我一點思路

package test;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class T extends JFrame implements Runnable,ActionListener
{
private int minutes;
private static double seconds;
private Thread mb;
private boolean isRun;
private Button start,stop,reset;
private Label desplay;
T(){
start=new Button("開始");
stop=new Button("停止");
reset=new Button("重置");
desplay=new Label();
this.setLayout(null);
desplay.setBounds(0,30,200,50);
start.setBounds(0,80,50,50);
stop.setBounds(60,80,50,50);
reset.setBounds(120,80,50,50);
refresh();
add(desplay);
add(start);
start.addActionListener(this);
stop.addActionListener(this);
reset.addActionListener(this);
add(stop);
add(reset);
setSize(300,200);
show();
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public static void main(String[] args)
{
new T();
}
public void run(){
while(isRun){
try{
seconds+=0.001d;
Thread.sleep(1);
if(seconds>59d){
seconds=0d;
minutes=minutes+1;
System.out.print(minutes);
}
refresh();
}
catch(Exception e){}
}
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("開始")){
startCount();
}
else if(e.getActionCommand().equals("停止")){
stopCount();
}
else{
reset();
}
}
public void refresh(){
desplay.setText(toString());
}
public void startCount(){
if(!isRun){
isRun=true;
mb=new Thread(this);
mb.start();
}
}
public void stopCount(){
if(isRun){
isRun=false;
}
}
public void reset(){
isRun=false;
minutes=0;
seconds=0d;
refresh();
}
public int getMinute(){
return minutes;
}
public double getSecond(){
return seconds;
}
public int getTotalTime(){
return minutes+(int)(seconds*1000);
}
public String toString(){
return ""+minutes+":"+(int)seconds+":"+(int)((seconds-(int)seconds)*1000);
}
}

⑶ 求一個java秒錶代碼

package info.bioz.test;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Date;
import java.text.SimpleDateFormat;

/**
* <p>File: StopWatch.java</p>
* <p>Description: </p>
* <p><a href="http://www.bioz.info/">BIOZ.info</a> Copyright (c) 2004</p>
*
* @author <a href="mailto:[email protected]">Chance</a>
*/
public class StopWatch extends JFrame {
JButton btnStart,btnStop;
JLabel label;
Timer timer;
public StopWatch() {
label=new JLabel("00:00:00.000");
btnStart=new JButton("start");
btnStop=new JButton("stop");
final int delay=100;
final Date startTime=new Date();
final SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss.S");
final Action taskPerformer = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
//顯示時間
Date d=new Date(System.currentTimeMillis()-startTime.getTime()-28800000);
label.setText(sdf.format(d));
label.repaint();
}
};
btnStart.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
startTime.setTime(new Date().getTime());
timer=new Timer(delay, taskPerformer);
timer.start();
}
});
btnStop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
if(timer!=null&&timer.isRunning())
timer.stop();
}
});

Container c=getContentPane();
c.add(label,BorderLayout.NORTH);
c.add(btnStart,BorderLayout.CENTER);
c.add(btnStop,BorderLayout.SOUTH);
}

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});

}

private static void createAndShowGUI() {
StopWatch window=new StopWatch();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
}
}

希望我的回答能夠幫到你
祝好運!

⑷ 利用所學的JAVA語言知識,完成一個實現秒錶功能的程序,利用GUI界面設計: (1)在界面上方的

/**
*小小的計時器
*/
{

_LABEL_TEXT="00:00:00000";

//計數線程
privateCountingThreadthread=newCountingThread();

//記錄程序開始時間
privatelongprogramStart=System.currentTimeMillis();

//程序一開始就是暫停的
privatelongpauseStart=programStart;

//程序暫停的總時間
privatelongpauseCount=0;

privateJLabellabel=newJLabel(INITIAL_LABEL_TEXT);

=newJButton("開始");

privateJButtonresetButton=newJButton("清零");

=newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(thread.stopped){
pauseCount+=(System.currentTimeMillis()-pauseStart);
thread.stopped=false;
startPauseButton.setText("暫停");
}else{
pauseStart=System.currentTimeMillis();
thread.stopped=true;
startPauseButton.setText("繼續");
}
}
};

=newActionListener(){
publicvoidactionPerformed(ActionEvente){
pauseStart=programStart;
pauseCount=0;
thread.stopped=true;
label.setText(INITIAL_LABEL_TEXT);
startPauseButton.setText("開始");
}
};

publicTimerFrame(Stringtitle)throwsHeadlessException{
super(title);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocation(200,200);
setResizable(false);

setupBorder();
setupLabel();
setupButtonsPanel();

startPauseButton.addActionListener(startPauseButtonListener);
resetButton.addActionListener(resetButtonListener);

thread.start();//計數線程一直就運行著
}

//為窗體面板添加邊框
privatevoidsetupBorder(){
JPanelcontentPane=newJPanel(newBorderLayout());
contentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
this.setContentPane(contentPane);
}

//配置按鈕
privatevoidsetupButtonsPanel(){
JPanelpanel=newJPanel(newFlowLayout());
panel.add(startPauseButton);
panel.add(resetButton);
add(panel,BorderLayout.SOUTH);
}

//配置標簽
privatevoidsetupLabel(){
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(newFont(label.getFont().getName(),label.getFont().getStyle(),40));
this.add(label,BorderLayout.CENTER);
}

//程序入口
publicstaticvoidmain(String[]args){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exceptione){
e.printStackTrace();
}

TimerFrameframe=newTimerFrame("小小計時器");
frame.pack();
frame.setVisible(true);
}

{

publicbooleanstopped=true;

privateCountingThread(){
setDaemon(true);
}

@Override
publicvoidrun(){
while(true){
if(!stopped){
longelapsed=System.currentTimeMillis()-programStart-pauseCount;
label.setText(format(elapsed));
}

try{
sleep(17);//使時鍾顯得更亂
}catch(InterruptedExceptione){
e.printStackTrace();
System.exit(1);
}
}
}

//將毫秒數格式化
privateStringformat(longelapsed){
inthour,minute,second,milli;

milli=(int)(elapsed%1000);
elapsed=elapsed/1000;

second=(int)(elapsed%60);
elapsed=elapsed/60;

minute=(int)(elapsed%60);
elapsed=elapsed/60;

hour=(int)(elapsed%60);

returnString.format("%02d:%02d:%02d%03d",hour,minute,second,milli);
}
}
}

參考:http://blog.csdn.net/yidinghe/article/details/6468407

⑸ 用java編寫一個類實現秒錶的功能

java System.currentTimeMillis() 就是獲取當前的毫秒數
開始時記錄 istart= System.currentTimeMillis();

結束時 記錄 iend= System.currentTimeMillis();

分鍾就是 Math.round((iend-istart)/(60*1000));
那 秒數 就是 Math.round((iend-istart)/1000)%60

再開啟回一個定時器,定答時獲取 itmp= System.currentTimeMillis();計算分鍾和秒數 顯示出來
顯示動態在跳得秒和分

⑹ 利用java設計一個秒錶小程序,要求可以隨時暫停,隨時繼續。

寫一個循環從1開始到60之後重新繼續就原來的值加,或者用緩存還可以用Calendarc

⑺ 求大神詳細解析這個java秒錶設計、好心人留郵箱 我把程序發你

[email protected]
給我看看

⑻ Java程序,模擬秒錶

計時,就可以了額,有木有?System.currentTimeMillis()

⑼ 要求:一 課程設計內容:設計一個單片機秒錶,該秒錶可顯示00.000到99.999秒的時間

#include<reg52.h>
#include<intrins.h>
void Delay1ms(); //@11.0592MHz
int ms=0;
int s=0;

void main()
{
while(1)
{
Delay1ms();//延時函數
ms++;
if(ms>=1000) //經過一千毫秒
{
ms=0; //讓一千毫秒的變數清零
s++; //秒變數加一
}//這里得到的就是數據,看你通過什麼顯示,然後將兩個數據填寫進去就行
}
}
void Delay1ms() //@11.0592MHz
{
unsigned char i, j;

_nop_();
_nop_();
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
剛剛給你寫的

⑽ 如何用JAVA編寫一個秒錶小程序

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Clock {

public static void main(String[] args) throws Exception{
time();
}

private static void time() throws Exception{
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//定時任務
TimerTask task = new TimerTask() {
@Override
public void run() {
System.out.println("當前時間:"+format.format(new Date()));
}
};
//創建定時器
Timer timer = new Timer();
//開始時間
long delay = 0;
//延遲時間
long intevalPeriod = 1 * 1000;
//開始執行定時任務
timer.scheleAtFixedRate(task, delay, intevalPeriod);
}
}

熱點內容
武漢大學學生會輔導員寄語 發布:2021-03-16 21:44:16 瀏覽:612
七年級學生作文輔導學案 發布:2021-03-16 21:42:09 瀏覽:1
不屑弟高考成績 發布:2021-03-16 21:40:59 瀏覽:754
大學畢業證會有成績單 發布:2021-03-16 21:40:07 瀏覽:756
2017信陽學院輔導員招聘名單 發布:2021-03-16 21:40:02 瀏覽:800
查詢重慶2018中考成績查詢 發布:2021-03-16 21:39:58 瀏覽:21
結業考試成績怎麼查詢 發布:2021-03-16 21:28:40 瀏覽:679
14中醫醫師資格筆試考試成績查分 發布:2021-03-16 21:28:39 瀏覽:655
名著賞析課程標准 發布:2021-03-16 21:27:57 瀏覽:881
北京大學商業領袖高端培訓課程 發布:2021-03-16 21:27:41 瀏覽:919