File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flood Control (JButton)

 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anyway to implement a "flood control" to a button ?

for example, if the button X is pressed more than 3 times in 5 seconds, print "wait a minute to reuse"

thanks !
 
Norm Radder
Ranch Hand
Posts: 707
3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would saving the time of the last n presses in a list do it?
Then design an algorithm to test for the desired conditions.
 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good idea !

help me here bro please


[ August 05, 2008: Message edited by: Juan Manuel Alberto de los Santos ]
 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ August 05, 2008: Message edited by: Juan Manuel Alberto de los Santos ]
 
Rob Spoor
Sheriff
Pie
Posts: 20393
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some possible improvements:
1) you're storing Integers in your List. You know this. Yet when you retrieve them, you convert them to string, then retrieve the int value from them. Something you already have:


2) store the result of System.currentTimeMillis() in your list. No need to create a Date object, format it, then call toString on a String (?) and then parse that as seconds. System.currentTimeMillis() already returns the current moment in time, with an accuracy of 10-20ms mostly:
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just disable the button until it is allowed to be pressed again?
 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
insane improvement Rob !

thanks a lot

**

Gregg Bolinger how can i do that ?

i know about, setEnabled(false) , but how can i "disable the button until it is allowed to be pressed again" ??
 
Rob Spoor
Sheriff
Pie
Posts: 20393
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a timer.

When the button is pressed you disable it, and start the timer. That runs for 3 seconds, then reenables the button and disables itself.

Check out javax.swing.Timer for more info.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic