When te button is clicked:
- disable the button.
- Make a new thread, with a while loop in it.
- Check whether the startTime - currentTime is bigger then the needed time.
- If it is, enable the button.
You should pass the button as a parameter into the thread, so you can enable it.
The correct way to do this is with a Swing Timer, designed and optimised for exactly this kind of task:
when the button is clicked
disable the button
create and start a new javax.swing.Timer with
a delay equal to how long you want the button disabled for,
and an actionPerformed method that re-enables the button
Yes, a thread with a loop in the background would work, but at the expense of burning CPU as fast as it could for the entire delay. Also your re-enable code will run on the wrong thread (all Swing code should run on Swing's thread).
javax.swing.Timer uses the same timer/event queue as Swing itself uses for things like the delay before popping up a tooltip. It really is the only recommendable solution. http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...