This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Combination Lock for begginers  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Master Rancher
Posts: 3276
33
 
Daffy Duck
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Also posted at http://forums.codeguru.com/showthread.php?560913-Combination-Lock-for-begginers


Yeah, i know, i just want to improve that code
 
Rancher
Posts: 2814
96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Daffy,

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!