Author |
Message |
momospaceship
|
Posted: Tue Jun 10, 2008 1:14 pm Post subject: Help with Timer Class |
|
|
In my progragm, I am trying to stop user input using the timer class. The user enters words for 3 minutes but it stops when the timer finishes. Right now, when the time completes, the next method runs but once this method is complete, it doesnt continue to the main menu. Please look at the my program and tell me how I can fix it. Thank you.
Description: |
|
Download |
Filename: |
BoggleGame.java |
Filesize: |
22.23 KB |
Downloaded: |
175 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Fri Jun 13, 2008 9:18 am Post subject: RE:Help with Timer Class |
|
|
I need you to be more precise. I don't have RTP, so I don't have the HSA console class...so I can't run your code and determine what it's supposed to be doing.
Please give a more detailed explanation of exactly what flow-of-control you were expecting your program to exhibit. Tell us which method you were expecting user input in, and what you were expecting to happen when your Timer hits the scheduled event.
|
|
|
|
|
|
Light
|
Posted: Fri Jun 13, 2008 9:52 am Post subject: RE:Help with Timer Class |
|
|
I also do not have the HSA classes but i think your problem is in the BoggleGame constructor and in how you are using the Timer.
There is no need to have an event called using a timer, it just needlessly complicates your program. What you should do instead is something like:
Java: |
int timeAtStart = System. currentTimeMillis();
while (true)
{
askData ();
display ();
if (System. currentTimeMillis() - timeAtStart > 1000)
break;
}
|
This way askData and display will keep running in till 10 seconds pass.
You will have to restructure your code as this does not deal with what events the timer called and they will need to be added back in to this loop some how, witch is up to you. The idea is to get ride of the timer and replace it will a loop that does it all and breaks when the current time - the start time is more then how long you want it to run.
|
|
|
|
|
|
DemonWasp
|
Posted: Fri Jun 13, 2008 9:59 am Post subject: RE:Help with Timer Class |
|
|
Light's approach is definitely the easiest way to go. It'll solve your problem, with one slight difference from what you may have wanted: when the time runs out, the user will have all the time in the world to enter that last word in askData() before the program realises they've run out of time.
Probably a non-issue if this is a school project.
|
|
|
|
|
|
Light
|
Posted: Fri Jun 13, 2008 10:03 am Post subject: RE:Help with Timer Class |
|
|
Thats a good point DemonWasp witch i overlooked. An easy fix would be to add a check after the user enters something to see if there is time left or not and if there is not do not count it.
|
|
|
|
|
|
momospaceship
|
Posted: Fri Jun 13, 2008 11:53 am Post subject: Re: Help with Timer Class |
|
|
sorry for not being specific....
Oh well, i handed in my isp. thanks for the help anyway. my program is pathetic and im gonna fail. HORRAY!
thanks for trying to help tho
|
|
|
|
|
|
|