package converter; import javafx.application.Application; import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Converter extends Application { /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } private final ObservableList<Unit> metricDistances; private final ObservableList<Unit> usaDistances; private final DoubleProperty meters = new SimpleDoubleProperty(1); public Converter() { //创建度量距离的Unit对象,然后使用这些Unit实例化ConversionPanel。 metricDistances = FXCollections.observableArrayList( new Unit("厘米", 0.01), new Unit("米", 1.0), new Unit("千米", 1000.0)); //创建美国距离的Unit对象,然后使用这些Unit实例化ConversionPanel。 usaDistances = FXCollections.observableArrayList( new Unit("英寸", 0.0254), new Unit("英尺", 0.305), new Unit("码", 0.914), new Unit("英里", 1613.0)); } @Override public void start(Stage stage) { VBox vbox = new VBox( new ConversionPanel( "公制系统", metricDistances, meters), new ConversionPanel( "美国系统", usaDistances, meters)); Scene scene = new Scene(vbox); stage.setTitle("单位转换器"); stage.setScene(scene); stage.show(); } }
JavaFX:互操作性