Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 3163
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: 2710
92
  • 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.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!