Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to generate beep in Java?

$
0
0

generate beep sound in JavaThis simple snippet shows how to produce the Beep Sound in Java using the AWT Toolkit.

The key thing here is is the delay introduced in the subsequent beeps. Changing the delay between beeps, you can create different sound patterns or rythms. This beep can be used in games development or signalling the user for some input errors or for some sort of notification.


package com.livrona.snippets.audio;

/**
* This snippet shows how to produce series of Beep sounds.
*
* @author mvohra
*
*/

publicclass BeepProducer {

/**
* main(.) method
* @param args
*/

publicstaticvoid main(String[] args) {

int beepCount =10;
for (int i =0; i < beepCount; ++i) {
System.out.println("Beep : "+ i);
// Ring the bell again using the Toolkit
java.awt.Toolkit.getDefaultToolkit().beep();
try {
Thread.sleep(1000); // introduce delay
} catch (InterruptedException e) {
}
}

} // end of main( )
} // end of Beep Producer





Viewing all articles
Browse latest Browse all 178

Trending Articles