JButton feedback

Can I get some ideas about how to combat a user repeatedly clicking a button effectively launching a DOS attack on the app! How can I limit the number of clicks (within a reasonable time frame of course) to prevent this happening?
LVL 17
krakatoaAsked:
Who is Participating?
 
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
You could do it in the actionPerformed () method itself. Maintain a record of the last-time when the button was clicked. Use getSource () to check if the button-source is same and search for its last-click-time. If the current-time is within some predefined time-frame, ignore the click and exit the method.
0
 
aviadbdCommented:

Cant you just have a member, "clickButton = false" set to "true" when teh button is clicked, and check if its false before starting the action?
0
 
aviadbdConnect With a Mentor Commented:

You can also inherit JButton and override the fireActionPerformed() and fireItemStateChanged() methods, to fire only once per limited time frame, or at all.

AviadBD.
0
 
krakatoaAuthor Commented:
I'll give both of these some thought. ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.