I want to alert the user in a Swing application of certain events with an old fashioned PC Speaker beep (NOT the soundcard), since not on every PC there is a soundcard with an attached speaker, or volume might be turned to zero, or a headphone might be connected... How can I do this?
UPDATE: java.awt.Toolkit.getDefaultToolkit().beep() seems usually to generate a sound on the soundcard. It only uses the speaker if there is no active soundcard. To print an ASCII value 7 works only if the application is launched in a terminal, which at least a Swing app usually isn't. So the question is still open.
Play a Windows sound Tag(s): IO You can access a sound as defined in the Windows configuration for specific event. The JDK exposed them as properties and the values for these properties are retrieved with the getDesktopProperty() method on java. awt. Toolkit.
Toolkit.getDefaultToolkit().beep();
Try this:
java.awt.Toolkit.getDefaultToolkit().beep();
It worked for me, although I'm not sure whether this was the PC Speaker beep or some OS-generated beep.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With