Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please add an abstract class and interface to this java program . Main.java //Imports: import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.scene.Scene; import

Please add an abstract class and interface to this java program .

Main.java

//Imports: import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage;

//Application Class public class Main extends Application {

Stage window; TableView table; TextField nameInput, priceInput, quantityInput;

public static void main(String[] args) { launch(args); }

@Override public void start(Stage primaryStage) throws Exception { window = primaryStage; window.setTitle("JoeyWhitmore - JavaFX");

//Name column TableColumn nameColumn = new TableColumn<>("Name"); nameColumn.setMinWidth(200); nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));

//Price column TableColumn priceColumn = new TableColumn<>("Price"); priceColumn.setMinWidth(100); priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));

//Quantity column TableColumn quantityColumn = new TableColumn<>("Quantity"); quantityColumn.setMinWidth(100); quantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity"));

//Name input nameInput = new TextField(); nameInput.setPromptText("Name"); nameInput.setMinWidth(100);

//Price input priceInput = new TextField(); priceInput.setPromptText("Price");

//Quantity input quantityInput = new TextField(); quantityInput.setPromptText("Quantity");

//Button Button addButton = new Button("Add"); addButton.setOnAction(e -> addButtonClicked()); Button deleteButton = new Button("Delete"); deleteButton.setOnAction(e -> deleteButtonClicked());

HBox hBox = new HBox(); hBox.setPadding(new Insets(10,10,10,10)); hBox.setSpacing(10); hBox.getChildren().addAll(nameInput, priceInput, quantityInput, addButton, deleteButton);

table = new TableView<>(); table.setItems(getProduct()); table.getColumns().addAll(nameColumn, priceColumn, quantityColumn);

VBox vBox = new VBox(); vBox.getChildren().addAll(table, hBox);

Scene scene = new Scene(vBox); window.setScene(scene); window.show(); }

//Add button clicked public void addButtonClicked(){ Product product = new Product(); product.setName(nameInput.getText()); product.setPrice(Double.parseDouble(priceInput.getText())); product.setQuantity(Integer.parseInt(quantityInput.getText())); table.getItems().add(product); nameInput.clear(); priceInput.clear(); quantityInput.clear(); }

//Delete button clicked public void deleteButtonClicked(){ ObservableList productSelected, allProducts; allProducts = table.getItems(); productSelected = table.getSelectionModel().getSelectedItems();

productSelected.forEach(allProducts::remove); }

//Get all of the products public ObservableList getProduct(){ ObservableList products = FXCollections.observableArrayList(); products.add(new Product("Tires", 120, 4)); products.add(new Product("Gum", 1.50, 15)); products.add(new Product("Bricks", 1.99, 250)); products.add(new Product("Laptop", 999.99, 1)); products.add(new Product("Pizza", 8.99, 8)); return products; }

}

Product.java

public class Product {

private String name; private double price; private int quantity;

public Product(){ this.name = ""; this.price = 0; this.quantity = 0; }

public Product(String name, double price, int quantity){ this.name = name; this.price = price; this.quantity = quantity; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public double getPrice() { return price; }

public void setPrice(double price) { this.price = price; }

public int getQuantity() { return quantity; }

public void setQuantity(int quantity) { this.quantity = quantity; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago