Structure of the Problem Requirements
In this problem we will learn how to make a sound in Java program. Before this tutorial we upload program how to make sound in C++. In both case Beep function is used. In Java Beep exist in java.awt.Toolkit class. In this problem we used for loop and used a thread which play the sound continuously. Through Beep function beginners student can easily make a small security system which help them to understand it more clearly. Here is the source code of this problem which help you in better understanding.
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 ");
}
}
}
}
}
Output of the program
Beep function in Java |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
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 ??