我想复制汽车油箱,该油箱将显示当前的百分比含量,同时加油量将与油箱中的油量成比例地减少。如果燃油下降到一定量,可能会改变背景颜色。有任何想法吗?我正在学习,并且开始放弃。从昨天开始,我一直在为此奋斗。
必要的班级字段
public class Car extends Vehicle {
private double fuel;
private final double fuelCapacity = 54;
private double fuelUsage = 7.4;
private double carMileage = 0.000;
private double distancePerSec;
private double fuelPerSec;
private final int carMaxSpeed = 215;
private double currentCarSpeed;
public void fuelUsagePerSecond() throws InterruptedException {
if (getStatus() == MOVING && fuel > 0) {
fuelUsage = fuelUsage + (getCurrentCarSpeed() / 25);
fuelPerSec = fuelUsage / 3600;
fuel = fuel - fuelPerSec;
}
else if (fuel <= 0){
Car.super.stop();
fuel = 0;
}
}
}
如何使用Java fx做到这一点?