/** * @author Sergej Borissov * @date: 23.08.2021 * @idee: Umkehrung der Page Counter Idee zum zählen der geschriebenen Seiten etc. * * */ public class WriteStarter extends Application { final int minutesPerHour = 60; final int pagesDefaultBook = 300; final int pagesPerHour = 4; final int daysPerWeek = 7; final int daysPerMonth = 30; final int daysPerYear = 365; public float calculatePagesWeek(){ return pagesPerHour * daysPerWeek; } public float calculatePagesMonth(){ return pagesPerHour * daysPerMonth; } public float calculateBooksYear(){ return (pagesPerHour * daysPerYear) / pagesDefaultBook; } public float calculateBooks30Years(){ return pagesPerHour * daysPerYear * 30 / pagesDefaultBook; } public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Pages n Write Counter 2021"); primaryStage.setMaxWidth(800); primaryStage.setMinHeight(700); VBox vBox = new VBox(); CategoryAxis xAxis = new CategoryAxis(); NumberAxis yAxis = new NumberAxis(); LineChart<String, Number> lineChart = new LineChart<String, Number>(xAxis,yAxis); lineChart.setStyle("-fx-border-color: blue"); XYChart.Series<String, Number> series1 = new XYChart.Series<String, Number>(); XYChart.Data<String, Number> pagesPerWeek = new XYChart.Data<>("Schreibseiten pro Woche: ", 0); XYChart.Data<String, Number> pagesPerMonth = new XYChart.Data<>("Schreibseiten pro Monat: ", 0); XYChart.Data<String, Number> booksPerYear = new XYChart.Data<>("Bücher pro Jahr: ", 0); XYChart.Data<String, Number> booksPer30Years = new XYChart.Data<>("Bücher in 30 Jahren ", 0); series1.getData().addAll(pagesPerWeek,pagesPerMonth, booksPerYear, booksPer30Years); TextField textField = new TextField("Hier Eingabe in Minuten"); textField.setMinWidth(230); textField.textProperty().addListener((observable, oldValue, newValue) -> { if (newValue != null) { try { pagesPerWeek.setYValue(Float.parseFloat(newValue) / minutesPerHour * calculatePagesWeek()); pagesPerMonth.setYValue(Float.parseFloat(newValue) / minutesPerHour * calculatePagesMonth()); booksPerYear.setYValue(Float.parseFloat(newValue) / minutesPerHour * calculateBooksYear() ); booksPer30Years.setYValue(Float.parseFloat(newValue) / minutesPerHour * calculateBooks30Years()); } catch (NumberFormatException ex) { ex.printStackTrace(); } } }); lineChart.getData().add(series1); vBox.getChildren().addAll(lineChart, textField); primaryStage.setScene(new Scene(vBox)); primaryStage.show(); } }