SavingsCalculator
unknown
java
4 years ago
3.8 kB
4
Indexable
package application; import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.chart.LineChart; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.scene.control.Label; import javafx.scene.control.Slider; import javafx.scene.chart.NumberAxis; import javafx.geometry.Pos; import javafx.scene.chart.XYChart; public class SavingsCalculatorApplication extends Application { @Override public void start(Stage window) throws Exception { BorderPane mainBorderPane = new BorderPane(); NumberAxis xAxis = new NumberAxis(0, 30, 1); NumberAxis yAxis = new NumberAxis(0, 20000, 2500); LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis); mainBorderPane.setCenter(lineChart); VBox vBox = new VBox(); BorderPane firstBorderPane = new BorderPane(); firstBorderPane.setPadding(new Insets(20, 20, 20, 20)); Label firstBorderPaneText = new Label("Monthly savings"); Slider firstBorderPaneSlider = new Slider(25, 250, 50); firstBorderPaneSlider.setShowTickMarks(true); firstBorderPaneSlider.setShowTickLabels(true); Label firstSliderExplanationText = new Label("25"); vBox.setAlignment(Pos.CENTER); firstBorderPane.setLeft(firstBorderPaneText); firstBorderPane.setCenter(firstBorderPaneSlider); firstBorderPane.setRight(firstSliderExplanationText); XYChart.Series savings = new XYChart.Series(); double x = 0; int y = 0; for (int i = 0; i < 60; i++) { savings.getData().add(new XYChart.Data(x, y)); x += 0.5; y += 300; } lineChart.getData().add(savings); firstSliderExplanationText.textProperty().bind(Bindings.format("%.1f", firstBorderPaneSlider.valueProperty())); firstBorderPaneSlider.valueProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { int currentValue = (int) firstBorderPaneSlider.getValue(); int doTimes = currentValue / 25; } }); BorderPane secondBorderPane = new BorderPane(); secondBorderPane.setPadding(new Insets(20, 20, 20, 20)); Label secondBorderPaneText = new Label("Yearly interest rate"); Slider secondBorderPaneSlider = new Slider(0, 10, 2.33); secondBorderPaneSlider.setShowTickLabels(true); secondBorderPaneSlider.setShowTickMarks(true); Label secondSliderExplanationText = new Label("2.33"); secondSliderExplanationText.textProperty().bind(Bindings.format("%.2f", secondBorderPaneSlider.valueProperty())); secondBorderPane.setLeft(secondBorderPaneText); secondBorderPane.setCenter(secondBorderPaneSlider); secondBorderPane.setRight(secondSliderExplanationText); vBox.getChildren().addAll(firstBorderPane, secondBorderPane); mainBorderPane.setTop(vBox); Scene scene = new Scene(mainBorderPane, 800, 600); window.setScene(scene); window.show(); } public static void main(String[] args) { launch(SavingsCalculatorApplication.class); } }
Editor is loading...