views:

204

answers:

3

Hi I am trying to write an application that will play morse code. I just wanted to know if there was a default system sound in java like some beep, or do I have to download some sound file from the internet?

+2  A: 

You can:

Print the ASCII bell character to the console (will emit a beep sound):

public class DoBeep {
    public static main(String args[]) {
        System.out.print("\007"); // bell ASCII char
        System.out.flush();
    }
}

Use the beep() method that will use the buzzer on the motherboard:

import java.awt.*;

public class DoBeep {
    public static void main(String args[]) {
        Toolkit.getDefaultToolkit().beep();     
    }
}
rogeriopvl
+1  A: 

Have a look at the Java Sound API, which can play MIDI tones.

kgiannakakis
There's been discussion of removing the MIDI output capabilities in Java 7.
R. Bemrose
+1  A: 

You may want to look at jMorse for some tips. This isn't to discourage you from your effort, but rather to provide a reference.

Michael Easter