From 78a3aeefb5b8310a297b20036146a9451a822d8d Mon Sep 17 00:00:00 2001 From: Harry Linrui XU <xulr0820@hotmail.com> Date: Wed, 22 Mar 2023 14:37:42 +0100 Subject: [PATCH] Added a DatePicker to the dialog box for testing --- .../demo/controller/AddExpenseController.java | 24 ++++++++++++------- src/main/resources/view/AddExpense.fxml | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java index 273c819f..0614e78c 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java @@ -1,6 +1,7 @@ package no.ntnu.idatt1002.demo.controller; import java.text.NumberFormat; +import java.time.LocalDate; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; @@ -8,6 +9,7 @@ import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; +import javafx.scene.control.DatePicker; import javafx.scene.control.TextField; import javafx.stage.Stage; import no.ntnu.idatt1002.demo.data.Economics.Expense; @@ -15,7 +17,7 @@ import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory; public class AddExpenseController { Expense newExpense = null; //the expense that is chosen when editing or the expense that is created when adding - Expense oldExpense = null; //an expense that is meant to track the old state of an expense before editing, in case cancel bugtton is clicked + Expense chosenExpense = null; //an expense that is meant to track the old state of an expense before editing, in case cancel bugtton is clicked @FXML private Button cancelBtn; @@ -25,6 +27,9 @@ public class AddExpenseController { @FXML private TextField dateField; + @FXML + private DatePicker datePicker; + @FXML private TextField descriptionField; @@ -70,13 +75,16 @@ public class AddExpenseController { @FXML public void pressOkBtn(ActionEvent event) { - String date = dateField.getText(); - double amount = Double.parseDouble(amountField.getText()); - String description = descriptionField.getText(); - ExpenseCategory category = getCategory(); - boolean recurring = isRecurring(); - newExpense = new Expense(description, amount, recurring, category, date); - System.out.println(date + " " + amount + " " + description + " " + category + " " + recurring); + if (newExpense == null) { + String date = dateField.getText(); + double amount = Double.parseDouble(amountField.getText()); + String description = descriptionField.getText(); + ExpenseCategory category = getCategory(); + boolean recurring = isRecurring(); + newExpense = new Expense(description, amount, recurring, category, date); + System.out.println(date + " " + amount + " " + description + " " + category + " " + recurring); + } + final Node source = (Node) event.getSource(); ((Stage) source.getScene().getWindow()).close(); diff --git a/src/main/resources/view/AddExpense.fxml b/src/main/resources/view/AddExpense.fxml index 67cb0b9c..db41d454 100644 --- a/src/main/resources/view/AddExpense.fxml +++ b/src/main/resources/view/AddExpense.fxml @@ -3,6 +3,7 @@ <?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.ComboBox?> +<?import javafx.scene.control.DatePicker?> <?import javafx.scene.control.DialogPane?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.TextField?> @@ -33,7 +34,6 @@ <Label text="Description:" GridPane.rowIndex="2" /> <Label text="Category" GridPane.rowIndex="3" /> <Label text="Recurring" GridPane.rowIndex="4" /> - <TextField fx:id="dateField" promptText="1/1/23" GridPane.columnIndex="1" /> <TextField fx:id="amountField" promptText="100" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <TextField fx:id="descriptionField" promptText="(optional)" GridPane.columnIndex="1" GridPane.rowIndex="2" /> <ComboBox fx:id="categoryBox" prefWidth="150.0" promptText="Food" GridPane.columnIndex="1" GridPane.rowIndex="3" /> @@ -47,6 +47,8 @@ <Insets top="20.0" /> </GridPane.margin> </HBox> + <DatePicker fx:id="datePicker" GridPane.columnIndex="2" /> + <TextField fx:id="dateField" GridPane.columnIndex="1" /> </children> </GridPane> </content> -- GitLab