java课程设计秒表
⑴ 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秒表设计、好心人留邮箱 我把程序发你
⑻ 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);
}
}