This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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.

 
Rancher
Posts: 3353
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
 
Master Rancher
Posts: 3036
106
  • 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.
 
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
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!