473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help on TIMER

Hii, I have this program and i need help on printing out the total time, can anyone help me on this?

If there is a better way to do this let me know
Thnx


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

public class MyTimer{

public static void main (String [] args){

class TimeListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
//...
}
}

ActionListener timeListen = new TimeListener();

Timer t = new Timer(1000, timeListen);
t.start();
JOptionPane.showMessageDialog(null, "Start timer");

//...

t.stop();
JOptionPane.showMessageDialog(null, "Stop timer");


System.out.println(t);

}
}
Nov 7 '06 #1
1 1950
Hii, I have this program and i need help on printing out the total time, can anyone help me on this?

If there is a better way to do this let me know
Thnx


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

public class MyTimer{

public static void main (String [] args){

class TimeListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
//...
}
}

ActionListener timeListen = new TimeListener();

Timer t = new Timer(1000, timeListen);
t.start();
JOptionPane.showMessageDialog(null, "Start timer");

//...

t.stop();
JOptionPane.showMessageDialog(null, "Stop timer");


System.out.println(t);

}
}


Hi , If your problem is to find the time taken for execution, you can try this:

public static void main (String [] args)
{
long start=System.currentTimeMillis()
................
...............

long end=System.currentTimeMillis()
......................
....................
}


It returns current time is millisecond, by dividing 1000 you can get time in seconds. Similarly you can get in minutes..
Nov 9 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: wukexin | last post by:
I write my own class Cfile, I want to know what about implement ctime().Who help me? My use function ctime, I sign it with $$$. my class Cfile: #------------------------ file.h...
9
by: tym | last post by:
HELP!!! I'm going round the twist with this... I have a VB6 application which is using DAO to access a database (Please - no lectures on ADO, I know what I'm doing with DAO!!) Ok, problem...
2
by: MyNameIsnt | last post by:
Can anyone tell me why, when I click on the buttons it register 2 characters on the display? if you use the right mousebutton it works ok, but the buttons dont flash?? it works fine without the...
2
by: Alfonso Morra | last post by:
Hi, I am writing a timer class that I want to be able to get to notify me (via a callback func), when a specified interval has elapsed. I have most of the timer functionality figured - however,...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
7
by: steve marchant | last post by:
trying to learn VB6. Simple counting loop which counts to 8 in 1 sec intervals, then starts from 1 again and repeats. Have two Command buttons on the form. Cmd1 starts the counting, and I need to...
4
by: Lemune | last post by:
Hello everyone. I'm using vb 2005. I'm creating program that run as service on windows. And in my program I need to use timer, so I'm using timer object from component. I try my source code on...
11
by: Zilla | last post by:
I have the following simple program. I just want to be able to do math operations (+, -, =)on Timer sublcasses, but want to handle cases where either rhs or lhs is an intrinsic value, However, the...
3
by: mxmillercell | last post by:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace timertest {
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.