Assignment 6 - JavaFX FXML plus Files
This is an individual assignment. Identical code will not be accepted.
Task: create a functional JavaFX FXML application that uses data stored in a file.
Create the following before writing java code:
a text file named items.txt with the following content:
1:car:2:23000
2:personal computer:21:870
3:phone:37:800
interface.fxml document (use the Oracle Scene Builder to create the interface as shown in the picture below)
Content of the Eclipse project:
package named prog24178items.txt file saved in the prog24178 package
-
this file contains the items. Each line in this file represents an item. The line is split into fields by using the “:” character. Each line contains values in the following order: item id, item name, item quantity, item priceConfig interface created in the prog24178 package
-
this interface contains the public final variable of String type named “file” that stores the path and the name of the items.txt data file. For example, the value could be: “C:\\temp\\items.txt”DatabaseController class created in the prog24178 packagethis is the controller class that implements the functionality for the application (see the requirements in the description below)the DatabaseController must implement the Config interface so that you can access the defined in the interface “file” variableRunApp class created in the prog2417 packagethis is the class that starts the execution and loads the fxml documentthe RunApp must implement the Config interface so that you can access the defined in the interface “file” variableItem class created in the prog24178 packagethis is the storage class. An object of the Item class can store one item (represented by a line in the items.txt file)this class must have the following data members: id (int), item (string), quantity (int), price (double)this class must have two constructors: a) default no-arg constructor, b) four arguments constructor that can be used to create and populate item object with valuesthis class must have public getters and setters for all data membersthis class must have the toString() method that would return the item description using the following format:
Item [id=1, item=car, quantity=2, price=23000.0]
An ArrayList of Item type must be used to store all items used by the applicationinterface.fxml file saved in the prog24178 packagethis is the FXML document with the graphical interface for this application
Description:
when the application starts, it checks if a file named “items.txt” exists. If the file does not exist, then the application must create the filethe data from the file is loaded from the items.txt file when the Load Data from File button is clickedto load data, you have to read the content of the items.txt file line by line. Each line represents an item. So, use the lines to create objects of the Item class and add the created objects to the ArrayList of Item type.the application data is saved to the items.txt file when the Save Data to File button is clicked
-
when this button is clicked, take the content of the ArrayList containing items and save it in the items.txt file using the following format:
id:itemname:quantity:price
id:itemname:quantity:price
....
when the Add Item button is clicked, a new item is created from the data entered int the text fields and the item is added to the collection of itemsfor this, create a new Item object using the values entered int the text fields and add the created Item object to the ArrayList of itemsdo not forget to refresh the content of the list view control to show newly added itemwhen the item is selected in a list view, the selected item information is shown in the text fieldsfor this, determine the index of the selected item in the list view . Then use the index to find the item stored at that index in the ArrayList of items . The data of the found item should be displayed in the text fields of the graphical interface (id, item, quantity, price)after an item is selected in the list view:
-
the Modify Item button can be used to save changes made to any of the item properties (id, item, quantity, or price)
-
for this, find the index of the item selected in the list view and update the item stored at that index in the ArrayList of items with the new content
-
do not forget to refresh the content of the list view to show the updated item
-
the Remove button can be used to remove the item from the database
-
for this, find the index of the selected in the list view item and use that index to remove the item from the ArrayList of items
-
do not forget to refresh the content of the list view to show that the item was removed
-
Grading:
2 marks – graphical interface that closely resembles one in the picture below
8 marks – added functionality as described in the assignment description
Note 1: errors (the code does not run) in the submitted code will result in a 50% penalty
Note 2: you must use the names given in the assignment when giving names to .java files, fxml document as well as the text document containing the items
Submission: exported Eclipse project – please note that you must submit the exported Eclipse project; the separately uploaded .java files will no be marked
Note: the selected control is the ListView showing the list of items loaded from the items.txt file.