Friday, 17 March 2017

java calls bios beep

to play beep there are several recommendations online, but none of them are perfectly working for me.

below command will use your speaker, not bios:

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


and below command never work on my computer:

System.out.print( (char)7 );

System.out.print( "\0007");


below command is a possible solution:

Runtime.getRuntime().exec("beep.exe");


Then i found this:

http://www.wikihow.com/Make-CMD-Beep


however i don't want make it run xxxx.exe for windows, my code may run on mac, of cause i can do try catch..... but i don't want to write anything for specific platform. if it run then it is run it not, then it should have no problem.  my solution is: 

System.out.println()

it is just printing, which will be able to work on any platform.

so i use the link above to put ^G into a file, 

then open it with a notepad, copy it, (it is a black dot or a square )

then use notepad to create a java fille:

package xxxx;

public class Beep{
public void play() {
System.out.println(" " );
}
public static void main (String[] args) {
new Beep().play();
}


Please use notepad and manually type,  don't copy!!!!

then call beep by:  new Beep().play();





 

No comments:

Post a comment