Java – why toolkit getDefaultToolkit(). Beep() does not work in windows?

When I try to use toolkit getDefaultToolkit(). When beep() beeps, it doesn't seem to run on any of my windows computers I know someone with the same problem, but they say it applies to other operating systems Who knows why?

Solution

This code is applicable to Windows 7. Please make sure your voice is not muted

import java.awt.*;

public class Beep {
    public static void main(String... args) {
        Toolkit.getDefaultToolkit().beep();     
    }
}

You can also print only the ASCII representation of the ringtone, which is also applicable to Windows 7

public class Beep {
    public static main(String... args) {
       System.out.print("\007"); // \007 is the ASCII bell
       System.out.flush();
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>