blueJ countdown timer

hi, im designing a small game and i kinda wanted to put like a countdown timer in, for example, if the user does something wrong then, a timer wil begin and they will have like 5 minutes to complete the game.

2 do this will i need to write another class etc or is there any function in java.util

i could import and use

thnx chias

[355 byte] By [chiasa] at [2007-11-27 3:08:31]
# 1
Do you know about the [url= http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()]System.currentTimeMillis()[/url] method?
CaptainMorgan08a at 2007-7-12 3:56:39 > top of Java-index,Java Essentials,New To Java...
# 2

o right cool,

so, does this read the clock that is on the pc,

and if this is the case, when the person does something wrong, can i use so that it reads the current time, then perharps add 5 minuets to that, and use an if statement and a while loop:

while time does not equal [time user made a mistake + 5minutes]

if time = time user made a mistake + 5minutes]

end game

i dont know if that makes sence hopefully it will

thnx chias

chiasa at 2007-7-12 3:56:39 > top of Java-index,Java Essentials,New To Java...
# 3
i think i got the System.currentTimeMillis() print correctly, and by reading the link you suggest i think that it prints the time in milliseconds..how would i change this to hours:minutes:secondsthnx chias
chiasa at 2007-7-12 3:56:39 > top of Java-index,Java Essentials,New To Java...
# 4
Try looking at the [url= http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html]Calendar[/url] class.
CaptainMorgan08a at 2007-7-12 3:56:39 > top of Java-index,Java Essentials,New To Java...
# 5

thnx when i use the methord Calendar.getInstance() it prints out loads of code but it does say what the hours, minute, second is at the end, and if i could get the 'HOUR' 'MINUTE' and 'SECOND' parts out of the Calendar.getInstance() call that would be more useful,

i tried Calendar.getHOUR();

but it says that method doesnt exist

can you give any clues what i need to do

chiasa at 2007-7-12 3:56:39 > top of Java-index,Java Essentials,New To Java...
# 6

If you just want a simple timer, you don't need the Calendar class, just use basic maths to calculate how many time has elapsed since the first System.currentTimeMillis() invocation,

1 second = 1000 milliseconds

1 minute = 60 seconds = 60 * 1000 milliseconds;

1 hour = 60 minutes = 60*60 seconds = 60*60*1000 milliseconds

Mensaje editado por:

Ruly-o_O

Ruly-o_Oa at 2007-7-12 3:56:39 > top of Java-index,Java Essentials,New To Java...