Un'altra soluzione, Windows dipendente è quello di utilizzare JNA e chiamare direttamente di Windows Beep function, disponibile in Kernel32. Sfortunatamente Kernel32 in JNA non fornisce questo metodo in 4.2.1, ma puoi facilmente estenderlo.
public interface Kernel32 extends com.sun.jna.platform.win32.Kernel32 {
/**
* Generates simple tones on the speaker. The function is synchronous;
* it performs an alertable wait and does not return control to its caller until the sound finishes.
*
* @param dwFreq : The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
* @param dwDuration : The duration of the sound, in milliseconds.
*/
public abstract void Beep(int dwFreq, int dwDuration);
}
Per utilizzarlo:
static public void main(String... args) throws Exception {
Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
kernel32.Beep(800, 3000);
}
Se si utilizza Maven è necessario aggiungere le seguenti dipendenze:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.2.1</version>
</dependency>
Per quanto ne so, è possibile un segnale acustico solo il segnale acustico di default : 'System.out.println (" \ 007 ");' – SimpleVar
Forse [questo] (http://stackoverflow.com/q/691743/1285418) può essere d'aiuto. –
@YoryeNathan: se l'output standard non va a una console, non verrà emesso alcun segnale acustico. –