Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-2010, 12:02 PM
Member
 
Join Date: Feb 2010
Posts: 12
Rep Power: 0
robc is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-09-2010, 12:07 PM
Senior Member
 
Join Date: Aug 2009
Posts: 2,193
Rep Power: 4
r035198x is on a distinguished road
Default
Where are you stuck?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-09-2010, 11:05 PM
Lil_Aziz1's Avatar
Senior Member
 
Join Date: Dec 2009
Location: United States
Posts: 341
Rep Power: 1
Lil_Aziz1 is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-10-2010, 12:06 AM
Member
 
Join Date: Feb 2010
Posts: 12
Rep Power: 0
robc is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-10-2010, 12:07 AM
Member
 
Join Date: Feb 2010
Posts: 12
Rep Power: 0
robc is on a distinguished road
Default
will thread.sleep() work in a web application and insert it into a database
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-10-2010, 07:49 AM
Senior Member
 
Join Date: Mar 2009
Posts: 464
Rep Power: 2
Singing Boyo is on a distinguished road
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
__________________
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!
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 02-11-2010, 12:52 AM
Member
 
Join Date: Feb 2010
Posts: 12
Rep Power: 0
robc is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 02-11-2010, 03:06 AM
Senior Member
 
Join Date: Mar 2009
Posts: 464
Rep Power: 2
Singing Boyo is on a distinguished road
Default
I was curious as to whether you were using java.sql to insert values into the database.

anyway, use somthing like this
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!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you create a simple timer? Arnold New To Java 2 11-01-2009 04:53 PM
beginner to create a countup timer taishan New To Java 3 11-13-2008 05:46 AM
EJB Timer mrjunsy Advanced Java 0 08-22-2008 04:09 PM
EJB Timer mrjunsy New To Java 0 08-04-2008 06:47 PM
How to cancel an individual timer in spite of canceling whole timer Java Tip java.util 0 04-04-2008 02:46 PM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:32 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org