Consider a java program that inventory management application of homework 6. A s
ID: 3829358 • Letter: C
Question
Consider a java program that inventory management application of homework 6. A solution to this homework is given at the end of this document. You can use this code or your own code in homework 6 as a basis for this assignment. Either way is fine.
For the fixed part of this homework (the 220 points) you must extend the program as follows:
Add a delete command.
Keep the inventory in alphabetical order. When a new item is to be added, put the entry into the appropriate location in the array.
Construct a Graphical User Interface (GUI) for the user. Do not use JOptionPane. You must use JavaFX.
Make the program object oriented. This means having a separate class for the internal representation of the inventory, with methods like add, list, or delete. It also means having a separate class for the GUI aspects of the program.
The program must follow the 10 Program Standards given with homework 4 (all previous homeworks are still posted in the folder “Previous homeworks”). These standards are reposted in a file called
Program Standards for Java Course.doc
For the optional part of this homework you may extend the program in various ways. Some areas for extension are as follows:
Usability and Aesthetics: Make the GUI especially pleasing to see and use. One example would be to make the list command give a nice listing.
Human Engineering: Provide good human engineering for the user. This means being very tolerant of user errors and making it easy to use. For example, you might give the user an option to name the inventory file, or you might check if the user tries to add another entry with the same name. Also, consider a simple Help command.
Reliability: Make the program especially reliable. Try to make it so that the program will not crash even under incorrect inputs. For example, handle a missing file well or prevent an array out of bounds error.
Maintainability: Make the program especially well structured and readable.
Functionality: Enhance to functionality of the program in various ways, even small ways.
For functionality, one enhancement would be to check that a find or enter command actually has a non-null string for the name. A little more work would be to check the validity of an item’s quantity. For instance, always verifying that an item’s quantity is greater than or equal to zero. An obvious enhancement could be a delete command.
For another example, one could allow a partial match to find or delete an entry. For example, “F po” would match any entry with “pop” in the name, for example “Pop” or “Popcorn” or “Potato”. You might use the function “find” in C++ for this feature.
Final Submission: Submitting a portfolio or dossier of sorts (a stapled or bound set of pages) containing
A separate cover page (or pages) itemizing the grounds for extra credit. It is your responsibility to itemize all grounds for extra credit.
A printout of your code,
A printout from several consecutive runs, illustrating the various features of your program. For example, you must show that the file I/O works.
A printout from the list command
In the sample runs, each of the commands "e", "f", "l", “d”, and "q" should be illustrated.
A solution similar to homework 6.
import java.io.*;
import java.util.*;
class Entry {
public String name, quantity, note;
}
public class InventoryFor1510 {
public static Entry[] entryList;
public static int num_entries;
public static Scanner stdin = new Scanner(System.in);
public static void main(String args[]) throws Exception{
int i;
char C;
String code, Command;
entryList = new Entry[200];
num_entries = 0;
Command = null;
C = ' ';
readInventory("inventory.txt");
System.out.println("Codes are entered as 1 to 8 characters. Use" +
" "e" for enter," +
" "f" for find," +
" "l" for listing all the entries," +
" "q" to quit.");
while(C != 'q'){
System.out.print("Command: ");
Command = stdin.next();
C = Command.charAt(0);
switch (C) {
case 'e':
addItem(); break;
case 'f':
code = stdin.next();
stdin.nextLine();
i = index(code);
if (i >= 0) displayEntry(entryList [i]);
else System.out.println("**No entry with code " + code); break;
case 'l':
listAllItems(); break;
case 's':
sortList(); break;
case 'q':
CopyInventoryToFile("inventory.txt");
System.out.println("Quitting the application. All the entries are "
+ "stored in the file inventory.txt"); break;
default:
System.out.println("Invalid command. Please enter the command again!!!"); }
}
}
public static void readInventory(String FileName) throws Exception {
File F;
F = new File(FileName);
Scanner S = new Scanner(F);
while (S.hasNextLine()) {
entryList [num_entries]= new Entry();
entryList [num_entries].name = S.next();
entryList [num_entries].quantity = S.next();
entryList [num_entries].note = S.nextLine();
num_entries++;
}
S.close();
}
public static void addItem() {
String name = stdin.next();
String quantity;
stdin.nextLine();
entryList [num_entries] = new Entry();
entryList [num_entries].name = name;
System.out.print("Enter Quantity: ");
quantity = stdin.nextLine();
entryList [num_entries].quantity = quantity;
System.out.print("Enter Notes: ");
entryList [num_entries].note = stdin.nextLine();
num_entries++;
}
public static int index(String Key) {
// Function to get the index of a key from an array
// if not found, returns -1
for (int i=0; i < num_entries; i++) {
if (entryList [i].name.equalsIgnoreCase(Key))
return i; // Found the Key, return index.
}
return -1;
}
public static void displayEntry(Entry item) {
System.out.println("--"+ item.name+" "+
item.quantity+" "+
item.note);
}
public static void listAllItems() {
int i = 0;
while (i < num_entries) {
displayEntry(entryList [i]);
i++;
}
}
public static void CopyInventoryToFile(String FileName) throws Exception{
FileOutputStream out = new FileOutputStream(FileName);
PrintStream P = new PrintStream( out );
for (int i=0; i < num_entries; i++) {
P.println(entryList [i].name + " " + entryList [i].number +
" " + entryList [i].note);
}
}
}
Explanation / Answer
Project_7_Main.java
import java.io.*;
import java.util.*;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.WindowEvent;
import javafx.util.Pair;
class Entry {
public String name, quantity, note;
}
public class Project_7_Main extends Application {
public static Entry[] entryList = new Entry[200];
public static int num_entries = 0;
public static Scanner stdin = new Scanner(System.in);
public static BorderPane pane = new BorderPane();
public static boolean debug = true;
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(pane, 800, 600);
primaryStage.setTitle("Inventory Managment");
pane.setStyle("-fx-background-color: #85CD66;"
+ "-fx-border-width: 5;"
+ "-fx-insets: 10;"
+ "-fx-border-radius: 5;"
+ "-fx-border-color: green;");
//Place nodes here
pane.setLeft(VisualInterface.getVBox());
//Create a scene and place it in stage
primaryStage.setScene(scene); //placing scene in stage
primaryStage.show();
primaryStage.setOnCloseRequest((WindowEvent w) -> {
try {
CopyInventoryToFile("inventory.txt");
}
catch (Exception e){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setContentText("There was a problem saving your changes!");
}
});
}
public static void main(String args[]) throws Exception {
readInventory("inventory.txt");
launch(args);
}
public static void readInventory(String FileName) throws Exception {
File F;
F = new File(FileName);
Scanner S = new Scanner(F);
while (S.hasNextLine()) {
entryList[num_entries] = new Entry();
entryList[num_entries].name = S.next();
entryList[num_entries].quantity = S.next();
entryList[num_entries].note = S.nextLine();
num_entries++;
}
S.close();
}
public static void enterName(String item) {
String itemName = "Item";
itemName = item;
}
public static void enterQuantity(String number) {
String quantity = "Quantity";
quantity = number;
}
public static void enterNotes(String notes) {
String itemNotes = "Notes";
itemNotes = notes;
}
public static int index(String Key) {
// Function to get the index of a key from an array
// if not found, returns -1
for (int i = 0; i < num_entries; i++) {
if (entryList[i].name.equalsIgnoreCase(Key)) {
return i; // Found the Key, return index.
}
}
return -1;
}
public static void displayEntry(Entry item) {
System.out.println("--" + item.name + " "
+ "--" + item.quantity + " "
+ "--" + item.note);
}
public static void listAllItems() {
int i = 0;
while (i < num_entries) {
displayEntry(entryList[i]);
i++;
}
}
public static void find(String search) {
for (int i = 0, found = 0; i < num_entries; i++){
if(search.toLowerCase().contains(entryList[i].name) || entryList[i].name.toLowerCase().contains(search)) {
results.add(entryList[i].name);
found++;
}
}
}
public static void delete(String name){
for(int i = 0; i < num_entries; i++) {
if(entryList[i].name.equals(editItem)) {
for(int j = i; j < num_entries; j++){
entryList[j] = entryList[j + 1];
}
num_entries--;
results.remove(editItem);
}
}
}
public static void sortList() {
int i;
Entry temp;
temp = new Entry();
for (int j = 0; j < num_entries; j++) {
for (i = j + 1; i < num_entries; i++) {
if (entryList[j].name.compareToIgnoreCase(entryList[i].name) > 0) {
//Swap the entries if their names are not in ascending order
temp = entryList[j];
entryList[j] = entryList[i];
entryList[i] = temp;
}
}
}
System.out.println("Sorted the list. Press l to list all the items");
}
public static void CopyInventoryToFile(String FileName) throws Exception {
FileOutputStream out = new FileOutputStream(FileName);
PrintStream P = new PrintStream(out);
for (int i = 0; i < num_entries; i++) {
P.println(entryList[i].name + " " + entryList[i].quantity
+ " " + entryList[i].note);
}
}
public static boolean isInteger(String quantity) {
Boolean digit = true;
int yourNumber;
for (int i = 0; i < num_entries; i++) {
try {
yourNumber = Integer.parseInt(quantity);
} catch (NumberFormatException ex) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setContentText("Invalid input. Quantity must be an integer. Quantity set to 0 by default.");
digit = false;
}
}
if (debug) {
System.out.println(digit);
}
return digit;
}
}
VisualInterface.java
import javafx.geometry.Insets;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.util.Pair;
public class VisualInterface {
public static ObservableList<String> results = FXCollections.observableArrayList();
public static Label findName = new Label();
public static String editItem;
public static VBox getVBox() {
VBox leftColumn = new VBox(15);
leftColumn.setStyle("-fx-background-image: url('http://images.freeimages.com/images/premium/previews/1932/19323130-fruits-and-vegetables-background.jpg');"
+ "-fx-border-width: 5;"
+ "-fx-insets: 10;"
+ "-fx-border-radius: 5;"
+ "-fx-border-color: white;");
Label optionLabel = new Label("Options");
DropShadow shadow = new DropShadow();
shadow.setOffsetX(5.0);
shadow.setOffsetY(5.0);
leftColumn.setPrefSize(200, 600);
leftColumn.setSpacing(40);
leftColumn.setPadding(new Insets(15, 5, 5, 5));
optionLabel.setMinWidth(100);
optionLabel.setFont(new Font("Rockwell Extra Bold", 35));
optionLabel.setTextFill(Color.WHITE);
optionLabel.setEffect(shadow);
leftColumn.getChildren().add(optionLabel);
Button btE = new Button("Enter");
Button btF = new Button("Find");
Button btD = new Button("Delete");
Button btL = new Button("List All");
Button btQ = new Button("Save");
Button[] options = {btE, btF, btD, btL, btQ};
for (int i = 0; i < options.length; i++) {
VBox.setMargin(options[i], new Insets(0, 0, 0, 15));
leftColumn.getChildren().add(options[i]);
options[i].setStyle("-fx-font: 30 Rockwell");
options[i].setMinWidth(150);
}
//------Handlers for 1st Enter Buttons----------------------//
btE.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
VBox enterBox = enterPane();
pane.getChildren().clear();
pane.getChildren().addAll(leftColumn, enterBox);
//Project_7_Main.addItem();
});
btF.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println();
}
VBox findBox = findPane();
pane.getChildren().clear();
pane.getChildren().addAll(leftColumn, findBox);
});
btD.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
VBox deleteBox = deletePane();
pane.getChildren().clear();
pane.getChildren().addAll(leftColumn, deleteBox);
});
btL.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
VBox listBox = listPane();
pane.getChildren().clear();
pane.getChildren().addAll(leftColumn, listBox);
});
btQ.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
VBox saveBox = savePane();
pane.getChildren().clear();
pane.getChildren().addAll(leftColumn, saveBox);
});
return leftColumn;
}
public static VBox enterPane() {
// Create the custom dialog.
Dialog<Pair<String, String>> dialog = new Dialog<>();
dialog.setTitle("Enter an item");
// Set the picture (must be included in the project).
//ImageView imageView = new ImageView(new Image("login.png"));
// Set the button types.
Button btnEnter = new Button("Enter");
btnEnter.setMinSize(60, 40);
Button btnCancel = new Button("Cancel");
btnCancel.setMinSize(60, 40);
VBox vBoxE = new VBox(15);
vBoxE.setPadding(new Insets(15, 15, 15, 15));
vBoxE.setPrefSize(500, 350);
vBoxE.setStyle("-fx-background-color: red;"
+ "-fx-border-width: 5;"
+ "-fx-insets: 10;"
+ "-fx-border-radius: 5;"
+ "-fx-border-color: gold;");
Label paneLabel = new Label("Enter an item");
paneLabel.setMinWidth(300);
paneLabel.setFont(new Font("Rockwell Extra Bold", 25));
HBox label = getHBox();
label.getChildren().add(paneLabel);
TextField name = new TextField();
name.setMinWidth(400);
Label nameLabel = new Label("Item: ");
nameLabel.setMinWidth(100);
nameLabel.setFont(new Font("Rockwell", 20));
HBox enterItem = getHBox();
enterItem.getChildren().addAll(nameLabel, name);
TextField quantity = new TextField();
quantity.setMinWidth(400);
Label numLabel = new Label("Quantity: ");
numLabel.setMinWidth(100);
numLabel.setFont(new Font("Rockwell", 20));
HBox enterNum = getHBox();
enterNum.getChildren().addAll(numLabel, quantity);
TextArea notes = new TextArea();
notes.setMinWidth(400);
notes.setWrapText(true);
notes.setMinHeight(250);
Label notesLabel = new Label("Notes: ");
notesLabel.setMinWidth(100);
notesLabel.setFont(new Font("Rockwell", 20));
HBox enterNotes = getHBox();
enterNotes.getChildren().addAll(notesLabel, notes);
HBox buttons = getHBox();
buttons.setTranslateX(350);
buttons.getChildren().addAll(btnEnter, btnCancel);
vBoxE.getChildren().addAll(label, enterItem, enterNum, enterNotes, buttons);
vBoxE.setTranslateX(200);
btnEnter.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
entryList[num_entries] = new Entry();
entryList[num_entries].name = name.getText();
entryList[num_entries].quantity = quantity.getText();
entryList[num_entries].note = notes.getText();
if (debug) {
System.out.println(entryList[num_entries].name + entryList[num_entries].quantity + entryList[num_entries].note);
}
num_entries++;
enterPane().getChildren().clear();
pane.getChildren().add(enterPane());
});
btnCancel.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
pane.getChildren().remove(vBoxE);
});
return vBoxE;
}
public static VBox findPane() {
VBox vBoxF = new VBox(15);
vBoxF.setPadding(new Insets(15, 15, 15, 15));
vBoxF.setPrefSize(500, 350);
Button btnEdit = new Button("Edit");
btnEdit.setMinSize(60, 40);
Button btnCancel = new Button("Cancel");
btnCancel.setMinSize(60, 40);
Label paneLabel = new Label("Enter an item");
paneLabel.setMinWidth(300);
paneLabel.setFont(new Font("Rockwell Extra Bold", 30));
HBox label = getHBox();
label.getChildren().add(paneLabel);
TextField findItem = new TextField();
findItem.setMinWidth(300);
Label nameLabel = new Label("Item: ");
nameLabel.setMinWidth(75);
nameLabel.setFont(new Font("Rockwell", 20));
HBox enterItem = getHBox();
enterItem.getChildren().addAll(nameLabel, findItem);
HBox buttons = getHBox();
buttons.setTranslateX(350);
buttons.getChildren().addAll(btnEdit, btnCancel);
ListView findResults = new ListView();
findResults.setMinWidth(395);
findResults.setTranslateX(15);
findResults.setMinHeight(300);
results.clear();
findResults.setItems(results);
vBoxF.getChildren().addAll(label, enterItem, findResults, buttons);
vBoxF.setTranslateX(200);
if(debug) findResults.setItems(results);
findItem.setOnKeyReleased((KeyEvent event) -> {
results.clear();
Project_7_Main.find(findItem.getText());
if (debug) {
System.out.println(results);
}
findResults.setItems(results);
});
findResults.setOnMouseClicked((MouseEvent m) -> {
editItem = findResults.getSelectionModel().getSelectedItem().toString();
});
btnEdit.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
findName.setText(findResults.getSelectionModel().getSelectedItem().toString());
if (debug) {
System.out.println(findResults.getSelectionModel().getSelectedItem().toString());
}
for (int i = 0; i < num_entries; i++) {
if (editItem.toLowerCase().contains(entryList[i].name.toLowerCase()) || entryList[i].name.toLowerCase().contains(editItem.toLowerCase())) {
pane.getChildren().remove(vBoxF);
pane.getChildren().add(editPane());
}
}
});
btnCancel.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
pane.getChildren().remove(vBoxF);
});
return vBoxF;
}
public static VBox editPane() {
// Set the button types.
Button btnEnter = new Button("Enter");
btnEnter.setMinSize(60, 40);
Button btnCancel = new Button("Cancel");
btnCancel.setMinSize(60, 40);
VBox vBoxEt = new VBox(15);
vBoxEt.setPadding(new Insets(15, 15, 15, 15));
vBoxEt.setPrefSize(500, 350);
vBoxEt.setStyle("-fx-background: gold");
findName.setMinWidth(300);
findName.setFont(new Font("Rockwell Extra Bold", 25));
HBox label = getHBox();
label.getChildren().add(findName);
TextField quantity = new TextField();
for (int i = 0; i < num_entries; i++) {
if(findName.getText().toLowerCase().contains(entryList[i].name.toLowerCase()))
quantity.setText(entryList[i].quantity);
}
quantity.setMinWidth(300);
Label numLabel = new Label("Quantity: ");
numLabel.setMinWidth(75);
numLabel.setFont(new Font("Rockwell", 15));
HBox enterNum = getHBox();
enterNum.getChildren().addAll(numLabel, quantity);
TextArea notes = new TextArea();
for (int i = 0; i < num_entries; i++) {
if(findName.getText().toLowerCase().contains(entryList[i].name.toLowerCase()))
notes.setText(entryList[i].note);
}
notes.setMinWidth(300);
notes.setWrapText(true);
notes.setMinHeight(250);
Label notesLabel = new Label("Notes: ");
notesLabel.setMinWidth(75);
notesLabel.setFont(new Font("Rockwell", 15));
HBox enterNotes = getHBox();
enterNotes.getChildren().addAll(notesLabel, notes);
HBox buttons = getHBox();
buttons.setTranslateX(350);
buttons.getChildren().addAll(btnEnter, btnCancel);
vBoxEt.getChildren().addAll(label, enterNum, enterNotes, buttons);
vBoxEt.setTranslateX(200);
btnEnter.setOnAction((ActionEvent e) -> {
if (debug)
System.out.println("clicked");
for (int i = 0; i < num_entries; i++) {
if(findName.getText().toLowerCase().contains(entryList[i].name.toLowerCase())) {
entryList[i].quantity = quantity.getText();
entryList[i].note = notes.getText();
}
}
try {
CopyInventoryToFile("inventory.txt");
}catch (Exception er){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setContentText("There was a problem saving your changes!");
}
});
btnCancel.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
pane.getChildren().remove(vBoxEt);
});
return vBoxEt;
}
public static VBox listPane() {
VBox vBoxL = new VBox(15);
vBoxL.setPadding(new Insets(15, 15, 15, 15));
vBoxL.setPrefSize(500, 350);
vBoxL.setStyle("-fx-background: gold");
Button btnEnter = new Button("Edit");
btnEnter.setMinSize(60, 40);
Button btnCancel = new Button("Cancel");
btnCancel.setMinSize(60, 40);
Button btnSort = new Button("Sort");
btnSort.setMinSize(60, 40);
Label paneLabel = new Label("All Items");
paneLabel.setMinWidth(300);
paneLabel.setFont(new Font("Rockwell Extra Bold", 30));
HBox label = getHBox();
label.getChildren().add(paneLabel);
ListView allResults = new ListView();
allResults.setMinWidth(395);
allResults.setTranslateX(15);
allResults.setMinHeight(300);
results.clear();
find("");
allResults.setItems(results);
HBox buttons = getHBox();
buttons.setTranslateX(300);
buttons.getChildren().addAll(btnSort, btnEnter, btnCancel);
vBoxL.getChildren().addAll(label, allResults, buttons);
vBoxL.setTranslateX(200);
allResults.setOnMouseClicked((MouseEvent m) -> {
editItem = allResults.getSelectionModel().getSelectedItem().toString();
});
btnSort.setOnAction((ActionEvent e) -> {
if (debug) System.out.println("clicked");
Project_7_Main.sortList();
pane.getChildren().remove(vBoxL);
pane.getChildren().add(listPane());
});
btnEnter.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
findName.setText(allResults.getSelectionModel().getSelectedItem().toString());
if (debug) {
System.out.println(allResults.getSelectionModel().getSelectedItem().toString());
}
pane.getChildren().remove(vBoxL);
pane.getChildren().add(editPane());
});
btnCancel.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
pane.getChildren().remove(vBoxL);
});
return vBoxL;
}
public static VBox deletePane() {
VBox vBoxD = new VBox(15);
vBoxD.setPadding(new Insets(15, 15, 15, 15));
vBoxD.setPrefSize(500, 350);
vBoxD.setStyle("-fx-background: gold;");
Button btnDelete = new Button("Delete");
btnDelete.setMinSize(60, 40);
Button btnCancel = new Button("Cancel");
btnCancel.setMinSize(60, 40);
Label paneLabel = new Label("Enter an item to delete");
paneLabel.setMinWidth(500);
paneLabel.setFont(new Font("Rockwell Extra Bold", 30));
HBox label = getHBox();
label.getChildren().add(paneLabel);
TextField delete = new TextField();
delete.setMinWidth(300);
Label nameLabel = new Label("Item: ");
nameLabel.setMinWidth(75);
nameLabel.setFont(new Font("Rockwell", 20));
HBox deleteItem = getHBox();
deleteItem.getChildren().addAll(nameLabel, delete);
HBox buttons = getHBox();
buttons.setTranslateX(350);
buttons.getChildren().addAll(btnDelete, btnCancel);
ListView items = new ListView();
items.setMinWidth(395);
items.setTranslateX(15);
items.setMinHeight(300);
results.clear();
items.setItems(results);
vBoxD.getChildren().addAll(label, deleteItem, items, buttons);
vBoxD.setTranslateX(200);
items.setOnMouseClicked((MouseEvent m) -> {
editItem = items.getSelectionModel().getSelectedItem().toString();
});
delete.setOnKeyReleased((KeyEvent event) -> {
results.clear();
Project_7_Main.find(delete.getText());
if (debug) {
System.out.println(results);
}
items.setItems(results);
});
btnDelete.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
Project_7_Main.delete(delete.getText());
items.setItems(results);
});
btnCancel.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
pane.getChildren().remove(vBoxD);
});
return vBoxD;
}
public static VBox savePane() {
VBox vBoxS = new VBox(15);
vBoxS.setPadding(new Insets(15, 15, 15, 15));
vBoxS.setPrefSize(500, 350);
vBoxS.setStyle("-fx-background: gold");
Button btnOk = new Button("OK!");
btnOk.setMinSize(60, 40);
Label paneLabel = new Label("Items saved!");
paneLabel.setMinWidth(300);
paneLabel.setAlignment(Pos.CENTER);
paneLabel.setFont(new Font("Rockwell Extra Bold", 30));
HBox label = getHBox();
label.getChildren().add(paneLabel);
HBox buttons = getHBox();
buttons.setTranslateX(400);
buttons.getChildren().addAll(btnOk);
vBoxS.getChildren().addAll(label, buttons);
vBoxS.setTranslateX(200);
btnOk.setOnAction((ActionEvent e) -> {
if (debug) {
System.out.println("clicked");
}
pane.getChildren().remove(vBoxS);
});
return vBoxS;
}
public static HBox getHBox() {
HBox hBox = new HBox(15);
hBox.setPadding(new Insets(15, 15, 15, 15));
hBox.setStyle("-fx-background: gold");
return hBox;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.