适用于 Windows 的 Java 电池计量表
我想为我的计算机制作一个电池表,这些计算机都在不同的操作系统上运行。我认为最好的方法是使用 Java。有没有办法无需外部库来做到这一点?它所需要做的就是在 java.swing.JProgressBar
中显示电池电量。
I want to make a battery meter for my computers, which all work on different OSs. I figured the best way would be in Java. Is there any way to do this WITHOUT external libraries? All it needs to do is show the battery level in a java.swing.JProgressBar
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,仅使用标准 JDK 是无法做到这一点的。由操作系统来公开有关当前电源/电池状态的详细信息,并且 Java 中没有内置的方法来访问此信息。要做你想做的事至少需要一些外部库,几乎肯定还需要 JNI。
No, there is no way to do this just using the standard JDK. It is up to the OS to expose details about the current power/battery state, and there is no built-in way to access this information in Java. To do what you want will require at least some external libraries, and almost certainly JNI as well.
即使在操作系统内,电池电量也是一个非常低级别的测量,实际上是由硬件执行的。
至少,您必须使用外部库来完成此操作,但即使您这样做,由于两个操作系统处理电池的方式非常不同,您仍然很可能无法获得跨平台解决方案和硬件。
Even within the OS, the battery level is a very low-level measurement that is really carried out by the hardware.
At the very least, you would have to use external libraries to do it, but even if you do, there's a good chance that you still wouldn't have a cross-platform solution due to the very different ways batteries are handled by both OS and hardware.