LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-22-2010, 06:13 PM   #1
Asido
Member
 
Registered: Jan 2010
Location: Denmark
Distribution: Gentoo, Archlinux, FreeBSD, Slackware
Posts: 84

Rep: Reputation: 24
Timer on event listener (Java)


Hello.
My question is: in example there is a KeyListener which waits for a particular button to be pressed. I need to make so that after the button is pressed once, the next several seconds it would be inactive. In other words, if I press it now, the keyPressed method would be executed, but after that the next 2 seconds I could spam the same button and nothing would be executed until the time is finished. After 2 seconds it becomes active again and once pressed would perform keyPressed method.
I hope you got the idea from my poor english.
 
Old 07-22-2010, 10:51 PM   #2
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
Allowing users to click on a button that doesn't respond only creates the impression that something is wrong with your application, even if it is by design. Swing components typically support a setEnabled function that will allow you to disable the button altogether so users have visual feedback about what is supposed to function and what is not. If you couple that feature with the sleep() function of the Thread class or a javax.swing.Timer object, you can control just how long it will take for the button to be re-enabled.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java JFrame and JPanel listener hunterfighter Programming 3 07-01-2009 09:28 AM
doubts about serialization of *Listener enent handler in java ... alred Programming 6 07-02-2006 07:14 PM
how to avoid writing every methods for a listener in a java program ?? alred Programming 2 05-24-2006 10:41 PM
Timer Event wallwaters Linux - Software 1 05-26-2005 09:46 PM
Java Timer alaios Programming 2 05-24-2004 01:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration