java 为什么 Toolkit.getDefaultToolkit().beep() 在 Windows 中不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15441910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does Toolkit.getDefaultToolkit().beep() not work in Windows?
提问by Daniel Causebrook
When I try to get a beep by using Toolkit.getDefaultToolkit().beep()
, it does not seem to work on any of my Windows computers. I also know someone who has the same problem, but they say it works on other OS's. Does anyone know why?
当我尝试使用 发出哔声时Toolkit.getDefaultToolkit().beep()
,它似乎在我的任何 Windows 计算机上都不起作用。我也知道有人有同样的问题,但他们说它适用于其他操作系统。有谁知道为什么?
采纳答案by syb0rg
This code works for me on Windows 7, make sure you don't have your sound muted.
此代码在 Windows 7 上适用于我,请确保您没有静音。
import java.awt.*;
public class Beep {
public static void main(String... args) {
Toolkit.getDefaultToolkit().beep();
}
}
You could also just print the ASCII
representation for the bell, also works on Windows 7
您也可以只打印ASCII
铃铛的表示,也适用于 Windows 7
public class Beep {
public static main(String... args) {
System.out.print("##代码##7"); // ##代码##7 is the ASCII bell
System.out.flush();
}
}
回答by Reto H?hener
For me, the problem was that I had "No Sounds" configured (Win7 Pro). After changing this back to "Windows Default", I was able to hear the beep (actually a 'ding') - also when started from within eclipse.
对我来说,问题是我配置了“无声音”(Win7 Pro)。将其改回“Windows 默认”后,我能够听到哔哔声(实际上是“叮”声) - 从 eclipse 中启动时也是如此。