Results 1 to 8 of 8

Thread: create a timer

  1. #1
    robc is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Question create a timer

    I have a website and I need to create a timer. I have two button the first button start the timer and add the time to the database and the second button stop the timer and add that time to the database. Can anyone help?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Where are you stuck?

  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    You can use Thread.sleep() and Thread.interrupt(). Or you can use the Timer Class: Java 2 Platform SE v1.3.1: Class Timer
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  4. #4
    robc is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default

    I'm not stuck at this moment. I am just try to do some research before I add this to my code. This is web application I did not mention this in my post. Can you help or put me in the right direction.

  5. #5
    robc is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default

    will thread.sleep() work in a web application and insert it into a database

  6. #6
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    ... we need more detail - are you running an applet, or a serverside sub-program? Are you hard-coding the database location and login into the java code itself, or using a separate set of code? Are you trying to get the time the timer is running, or the time the timer starts and the time the timer ends? (if the latter, use System.getCurrentTimeMillis() in the button actions!)

    Answer these and give us some more info, and we should be able to help you :D
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  7. #7
    robc is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default

    I'm using Weblogic, I guess that serverside. What you mean about hard coding the database? I'm trying get the timer starts and when the timer ends.

  8. #8
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    I was curious as to whether you were using java.sql to insert values into the database.

    anyway, use somthing like this
    Java Code:
    class TimeCounter{
         int startTime, endTime;
         //starts a TimeCounter
         public TimeCounter(){
              startTime = System.getCurrentTimeMillis();
         }
    
         public void endCounter(){
              endTime = System.getCurrentTimeMillis();
         }
         public int getFullTime(){
              return endTime-startTime;
         }
    }
    Attach it into your gui or whatever. Create a counter when you want to start the timer, and call endCounter to stop it. getFullTime returns the total number of milliseconds between creation and the call to endCounter.

    Best,
    SingingBoyo
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. How do you create a simple timer?
    By Arnold in forum New To Java
    Replies: 2
    Last Post: 11-01-2009, 05:53 PM
  2. beginner to create a countup timer
    By taishan in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 06:46 AM
  3. EJB Timer
    By mrjunsy in forum Advanced Java
    Replies: 0
    Last Post: 08-22-2008, 05:09 PM
  4. EJB Timer
    By mrjunsy in forum New To Java
    Replies: 0
    Last Post: 08-04-2008, 07:47 PM
  5. Replies: 0
    Last Post: 04-04-2008, 03:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •