+ 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
3 Respostas
+ 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)
+ 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);
        }
        
    }
}
0
use delay in loop



