我正在尝试设计一种简单的方法,但是由于某些原因而无法计算值:
public static void animateBattery()
{
float boxPercent = (58/100);
System.out.println( "boxPercent "+ boxPercent);
int batteryPercent = (int) Math.round(storageLimit / 100 * elecStored);
setBatteryColor(batteryPercent);
System.out.println( "batteryPercent "+ batteryPercent);
int storedPercent = (int) Math.round(boxPercent * batteryPercent);
System.out.println( "storedPercent "+ storedPercent);
System.out.println( "Another demonstration " + 58/100);
System.out.println( "One more " + 100);
batteryColor.setBounds(890, 405 + (58 - storedPercent), 81, storedPercent);
frame.getContentPane().add(batteryColor);
}
输出:
boxPercent 0.0
batteryPercent 0
storedPercent 0
Another demonstration 0
One more 100
希望我提供了足够的代码来解决问题。很抱歉成为菜鸟。任何帮助将不胜感激!