Hello,
I'm currently working on the dreaded Inventory Program. I'm on part four and just learning GUIs. I need to modify the Inventory Program to use a GUI. In the GUI, it should display the information in my array one line at a time as well as the value of my entire inventory, additional feature and restocking fee. I was able to create the GUI, but I can't populate it with my array items. Any tips on getting my array information to display on the GUI would be wonderful! I am able to compile the file, but get an empty GUI.
Any assistance is greatly appreciated!!!! !
Here is my array code and the dispaly call to the GUI in my Main class:
Here is my the code to my Labels class where I defined all the JLabels for the GUI:
I'm currently working on the dreaded Inventory Program. I'm on part four and just learning GUIs. I need to modify the Inventory Program to use a GUI. In the GUI, it should display the information in my array one line at a time as well as the value of my entire inventory, additional feature and restocking fee. I was able to create the GUI, but I can't populate it with my array items. Any tips on getting my array information to display on the GUI would be wonderful! I am able to compile the file, but get an empty GUI.
Any assistance is greatly appreciated!!!! !
Here is my array code and the dispaly call to the GUI in my Main class:
Code:
// constructor
public Inventory_Program4()
{
double totalInventoryValue = 0.0;
// Specify how many items are in the array
// instantiate Book2 object
myBook = new Book2[5];
myBook[0] = new Book2("The Key Triology", 1, 25, 7.99, "Nora Roberts");
myBook[1] = new Book2("The Shinning", 2, 15, 5.99, "Stephen King");
myBook[2] = new Book2("Wild Acre", 3, 7, 4.99, "Phillipa Gregory");
myBook[3] = new Book2("Dark Paradise", 4, 2, 12.99, "Tami Hoag");
myBook[4] = new Book2("Dollhouse Murders", 5, 18, 2.95, "Betty Ren Wright");
// call method sort book inventory for display
sortBookInventory();
for (int i = 0; i<5; i++)
{
// display the book title
System.out.println("The book title is: " + myBook[i].getBookTitle());
// display the item number
System.out.println("The item number is: " + myBook[i].getItemNumber());
// display the number of units in stock
System.out.println("The number of units in stock is: " + myBook[i].getBookUnits());
// display the price per book
System.out.printf("The price of the book is: $%.2f\n", myBook[i].getBookPrice());
// display the value of the inventory
System.out.printf("The value of the inventory is: $%.2f\n", myBook[i].inventoryValue());
// display the book author
System.out.println("The book author is: " + myBook[i].getBookAuthor());
// display the restocking fee
System.out.println("Restock Fee: " + myBook[i].inventoryValue() * 0.05);
// calculate total inventory value with restocking fee added
totalInventoryValue += (myBook[i].inventoryValue() * 1.05);
// insert blank line
System.out.println();
} // end for
// display the total value of the inventory with the restocking fee
System.out.printf("The total value of the book inventory including the restocking fee is: $%5.2f.\n", totalInventoryValue);
// display the total value of the inventory excluding the restocking fee
System.out.println("The total value of the book inventory is: " + totalInventoryValue());
// calling GUI to display contents
Labels labels = new Labels(); // create Labels
labels.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
labels.setSize(275, 180); // set frame size
labels.setVisible( true ); // display frame
} // end constructor
Code:
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
public class Labels extends JFrame
{
private JLabel bookTitleLabel;
private JLabel itemNumberLabel;
private JLabel bookUnitsLabel;
private JLabel bookPriceLabel;
private JLabel inventoryValueLabel;
private JLabel bookAuthorLabel;
private JLabel bookRestockingFeeLabel;
private JLabel totalInventoryValueLabel;
// Labels constructor adds JLabels to JFrame
public Labels()
{
super( "Inventory Program" );
setLayout( new FlowLayout() ); // set frame layout
// JLabel constructor
bookTitleLabel = new JLabel("Book Title:");
bookTitleLabel.setToolTipText("Book Title Label");
add( bookTitleLabel ); // add bookTitleLabel to JFrame
itemNumberLabel = new JLabel("Item Number:");
itemNumberLabel.setToolTipText("Item Number Label");
add( itemNumberLabel ); // add itemNumberLabel to JFrame
bookUnitsLabel = new JLabel("Book Units:");
bookUnitsLabel.setToolTipText("Book Units Label");
add( bookUnitsLabel ); // add bookUnitsLabel to JFrame
bookPriceLabel = new JLabel("Book Price:");
bookPriceLabel.setToolTipText("Book Price Label");
add( bookPriceLabel ); // add bookPriceLabel to JFrame
inventoryValueLabel = new JLabel("Book Inventory Value:");
inventoryValueLabel.setToolTipText("Inventory Value Label");
add ( inventoryValueLabel ); // add inventoryValueLabel to JFrame
bookAuthorLabel = new JLabel("Book Author:");
bookAuthorLabel.setToolTipText("Book Author Label");
add( bookAuthorLabel ); // add bookAuthorLabel to JFrame
bookRestockingFeeLabel = new JLabel("Restocking Fee:");
bookRestockingFeeLabel.setToolTipText("Restocking Fee Label");
add( bookRestockingFeeLabel ); // add bookRestockingFeeLabel to JFrame
totalInventoryValueLabel = new JLabel("Total Inventory Value:");
totalInventoryValueLabel.setToolTipText("Total Inventory Label");
add( totalInventoryValueLabel ); // add totalInventoryValueLabel to JFrame
} // end Label constructor
} // end class Labels
Comment