I want to make a battery meter for my computers, which all work on diffe开发者_如何学运维rent 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
.
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.
精彩评论