do I need to write it in the form? to run
Answered
import java.awt.Toolkit
import java.util.Timer
import java.util.TimerTask
/**
* Schedule a task that executes once every second.
*/
class AnnoyingBeep {
internal var toolkit: Toolkit
internal var timer: Timer
init {
toolkit = Toolkit.getDefaultToolkit()
timer = Timer()
timer.schedule(RemindTask(),
0, //initial delay
(1 * 1000).toLong()) //subsequent rate
}
internal inner class RemindTask : TimerTask() {
var numWarningBeeps = 3
override fun run() {
if (numWarningBeeps > 0) {
toolkit.beep()
println("Beep!")
numWarningBeeps--
} else {
toolkit.beep()
println("Time's up!")
//timer.cancel(); //Not necessary because we call System.exit
System.exit(0) //Stops the AWT thread (and everything else)
}
}
}
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("About to schedule task.")
AnnoyingBeep()
println("Task scheduled.")
}
}
}
Please sign in to leave a comment.

Could you please clarify the issue/question. If it is not IDE-specific I think it is better to use related development forums to get more relevant help. Thanks.