diff --git a/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/CartController.java b/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/CartController.java index 0b3ec89..3fc19d1 100644 --- a/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/CartController.java +++ b/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/CartController.java @@ -1,5 +1,7 @@ package com.example; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -42,25 +44,29 @@ public class CartController { @FXML private Label mainTitle; + // Observable list to hold cart items + private final ObservableList cartItems = FXCollections.observableArrayList(); + // Initialize method to set up the TableView @FXML public void initialize() { + // Set up columns to match Item properties nameColumn.setCellValueFactory(new PropertyValueFactory<>("name")); descriptionColumn.setCellValueFactory(new PropertyValueFactory<>("description")); quantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity")); priceColumn.setCellValueFactory(new PropertyValueFactory<>("price")); - // Populate the table with some sample data (replace with actual logic later) - cartContent.getItems().addAll( + // Populate the cart table with sample data for demonstration + cartItems.addAll( new Item("Book A", "A fascinating fantasy novel.", 1, 12.99), new Item("Book B", "A thrilling sequel.", 2, 10.50)); + cartContent.setItems(cartItems); } @FXML private void handleCartButton(ActionEvent event) { System.out.println("Cart button clicked!"); try { - // Navigate to the cart page (using the setRoot method from App) App.setRoot("cart"); } catch (IOException e) { e.printStackTrace(); @@ -71,7 +77,6 @@ public class CartController { private void handleLoginButton(ActionEvent event) { System.out.println("Login button clicked!"); try { - // Navigate to the login page App.setRoot("login"); } catch (IOException e) { e.printStackTrace(); @@ -80,10 +85,13 @@ public class CartController { @FXML private void handleCheckOutButton(ActionEvent event) { - System.out.println("Checkout button clicked!"); - // Add logic to proceed to checkout + if (cartItems.isEmpty()) { + System.out.println("Cart is empty. Cannot proceed to checkout."); + return; + } + + System.out.println("Proceeding to checkout..."); try { - // Navigate to the checkout page App.setRoot("checkout"); } catch (IOException e) { e.printStackTrace(); diff --git a/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/ShopController.java b/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/ShopController.java index 37e3a6c..392882c 100644 --- a/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/ShopController.java +++ b/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/java/com/example/ShopController.java @@ -78,9 +78,8 @@ public class ShopController { } @FXML - private void handleLoginButton() { - System.out.println("Login button clicked!"); - // Logic for handling login. + private void handleLoginButton() throws IOException { + App.setRoot("login"); } @FXML diff --git a/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/resources/com/example/cart.fxml b/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/resources/com/example/cart.fxml index ffb567b..142f89f 100644 --- a/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/resources/com/example/cart.fxml +++ b/Code/ost/JAVA-FX-PROJECT/_javafx_website_task/src/main/resources/com/example/cart.fxml @@ -15,17 +15,17 @@ - + -