Help on TIMER

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • enzoJava
    New Member
    • Nov 2006
    • 4

    #1

    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.Tim er;
    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.sho wMessageDialog( null, "Start timer");

    //...

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


    System.out.prin tln(t);

    }
    }
  • baskarpr
    New Member
    • Oct 2006
    • 33

    #2
    Originally posted by enzoJava
    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.Tim er;
    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.sho wMessageDialog( null, "Start timer");

    //...

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


    System.out.prin tln(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.cu rrentTimeMillis ()
    ............... .
    ...............

    long end=System.curr entTimeMillis()
    ............... .......
    ............... .....
    }


    It returns current time is millisecond, by dividing 1000 you can get time in seconds. Similarly you can get in minutes..

    Comment

    Working...