Lets learn how to create beep using java.
We can create a beep sound to indicate a warning or error by using java. However, it is often better to give a warning dialog box with a description about the problem using GUI interface.
There are two ways to produce the sound beep:
1.Using Toolkit class: We can create a beep using Toolkit class. For this we first need to import java.awt.Toolkit. This class provides beep() method to create beep sound. The following syntax is used to create beep using Toolkit class:
Use this statment in your code:
This is not always a sufficient way to alert the user as there may not be speakers on the user's computer.
2.Using ASCII value: ASCII refer as American Standard Code for Information Interchange. We use ASCII value "\007" to produce beep. As we are using in our example.
Here is the code of the program :
Liked it! Share this Tutorial