My project simulate combination lock at door. Somebody can tell me how to add a function that automatically requests a password after 20 seconds and also a function that changes the password but only if the door is open.
as I read from the other site, you do indeed have to add a Swing Timer. Unfortunately, that alone is not enough. To implement what you want you need some more logic.
But let me help you a little.
I added a Swing Timer, called timer, as a field in your class. I gave it this definiton in the constructor:
As you see, after 20 seconds a method 'processTimerEvent' is invoked.
This method I added to the class:
This is invoked when the user has not typed within 20 seconds the correct key.
Now, as you see, there are some more methods to be implemented, and you need to add some extra logic to the actionPerformed-method: if the user guesses correct, then for 20 or so seconds the door is open, but then the door closes, a new secret must be derived, and the timer must be started again.
Well, I hope this helps a little. As Norm writes, show us what you have so far, and possibly where you got stuck.
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database