+ 4

Plz can someone post a code to produce a beep(or any) sound(alert) every 3 mins.

The program should make the sound every 3 mins in an infinite loop

25th Jun 2017, 10:18 AM
Geetanjali Aich
Geetanjali Aich - avatar
3 ответов
+ 2
package sololearn.Answer; import java.awt.Toolkit; public class SoundPlayer { public static void main(String[] args) { int sleepDuration = (60 * 3) * 1000; Thread soundThread = new Thread(() -> { try { while (true) { Toolkit.getDefaultToolkit().beep(); Thread.sleep(); } } catch (InterruptedException e) { System.out.println(e); } catch (Exception e) { System.out.println(e); } }); soundThread.start(); } } (sry for bad formatting) This code will annoy you every 3 minutes with a warning sound. This code works fine under windows. If you want to run it on Linux, you should look into the tools java.sound.sampled provides. ( don't know if it works on a Mac)
25th Jun 2017, 3:19 PM
Kagemi
+ 2
the code is: import java.awt.Toolkit; public class Program { public static void main(String[] args)throws InterruptedException { int sleepDuration=5*1000;//5 sec interval Thread soundThread=new Thread(); while(true) {Toolkit.getDefaultToolkit().beep(); Thread.sleep(sleepDuration); } } }
2nd Jul 2017, 1:38 PM
Geetanjali Aich
Geetanjali Aich - avatar
0
use delay in loop
25th Jun 2017, 10:53 AM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar