Home Java Example Java Awt Beep Java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Beep Java

Advertisement
Lets learn how to create beep using java. We can create a beep sound to indicate a warning or error.

Beep Java

     

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:
import java.awt.Toolkit;
Use this statment in your code:
Toolkit.getDefaultToolkit().beep().
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 bee
p. As we are using in our example.

Here is the code of the program :

import java.util.*;
public class Beep{

 
  public static void main(String[] args) {

  if(args[0].equals("1"))
  System.out.println("\007");
  if(args[0].equals("2"))
  System.out.println("\007\007");
  if(args[0].equals("3"))
  System.out.println("\007\007\007");
  if(args[0].equals("4"))
  System.out.println("\007\007\007\007");
  if(args[0].equals("5"))
  System.out.println("\007\007\007\007\007");
  if(args[0].equals("6"))
  System.out.println("\007\007\007\007\007\007");
  if(args[0].equals("7"))
  System.out.println("\007\007\007\007\007\007\007");
  if(args[0].equals("8"))
  System.out.println("\007\007\007\007\007\007\007\007");
  }

}

Download this example.

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 19, 2007

Ask Questions?    Discuss: Beep Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Alistra
October 11, 2011
loops

loops are hard, let's go shoping
pawan
November 12, 2011
java

i satisfied for this website
DMCA.com