Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java equivalent of C# system.beep?

I am working on a Java program, and I really need to be able to play a sound by a certain frequency and duration, similarly to the c# method System.Beep, I know how to use it in C#, but I can't find a way to do this in Java. Is there some equivalent, or another way to do this?

using System;  class Program {     static void Main()     {     // The official music of Dot Net Perls.     for (int i = 37; i <= 32767; i += 200)     {         Console.Beep(i, 100);     }     } } 
like image 806
Glen654 Avatar asked May 27 '12 03:05

Glen654


People also ask

Is Java similar to C?

C is a middle-level language as it binds the bridges between machine-level and high-level languages. Java is a high-level language as the translation of Java code takes place into machine language, using a compiler or interpreter. C is only compiled and not interpreted. Java is both compiled and interpreted.

Is Java similar to C or C++?

These two languages are very similar in terms of syntax and language features. They are so similar that if you're shown some portion of C++ code from a project and asked whether it's C++ or Java code, you may confuse yourself.

Is Java built on C?

The very first Java compiler was developed by Sun Microsystems and was written in C using some libraries from C++. Today, the Java compiler is written in Java, while the JRE is written in C.

What is equivalent in Java?

equivalent(T, T) returns true if both values are null, or if neither value is null and Object. equals(java. lang. Object) returns true .


1 Answers

You can use this:

java.awt.Toolkit.getDefaultToolkit().beep(); 

EDIT

If you are trying to play anything of duration and with different sounds you should really look into the Java MIDI library. The default beep won't be able to meet your needs as you can't change the length of the beep.

http://www.oracle.com/technetwork/java/index-139508.html

like image 109
Hunter McMillen Avatar answered Sep 29 '22 10:09

Hunter McMillen