Beep function is used to produce any sound In Java. Beep function exists in java.awt.Toolkit class. In this program we used for loop and used a thread which play the sound continuously.
Source Code
package soundinjava; import java.awt.Toolkit; import java.util.Scanner; public class sound { public static void main (String args []) { int a; Scanner input = new Scanner (System.in); System.out.println(" \t \t \t LEP TUTORIALS \n"); System.out.println(" Do You Want to Play Sound? \n"); System.out.println(" 1. Start \n"); a = input.nextInt(); if (a ==1) { for(int i = 0 ; i < 100; i++){ Toolkit.getDefaultToolkit().beep(); try{ Thread.sleep(100); } catch(Exception e) { System.out.print("Sorry Sound Can't Play ! \n \n "); } } } } }
Why are you using Threads ????
ReplyDeleteIs there not working with out using threads ???
For play sound just use the Beep simple if it is for beginners ??