
如何写秒表程序
(C#)
秒表的表,就是这个表。
用JAVA写秒表
package 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; \\\/** *
File: StopWatch.java<\\\/p> *
Description: <\\\/p> *
BIOZ.info<\\\/a> Copyright (c) 2004<\\\/p> * * @author 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); } }
秒表的使用方法
最常见的是数字秒表,你指的是数字秒表吗
大字部分是正常的分,秒。
小字部分是秒后的两位小数。
读数结果是两部分数字相加,精确度为0.01秒,不需诂读如果是机械秒表,大表盘正常读秒,小表盘为精读,精度一般为0.01秒,需要估读。
结果也是两部分相加



