should display. the GUI using Java graphics classes.
Add a company logo to the GUI using Java graphics classes.
As far as I know, I have done this. If anyone could look at my code and point me in the right direction, it would be greatly appreciated. Also, I have to do this to the assignment by Sunday: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item.
• Add a Save button to the GUI that saves the inventory to a C:\data\inventory.dat file.
• Use exception handling to create the directory and file if necessary.
• Add a search button to the GUI that allows the user to search for an item in the inventory by the product name. If the product is not found, the GUI should display an appropriate message. If the product is found, the GUI should display that product’s information in the GUI.
I have yet to start on this part because I have yet to get the other part corrected. Any advice on the part that is due Sunday is also greatly appreciated. I have no idea even where to begin.
Here is all of my codes:
public class Fish extends Product {
public Fish(int number, String fishname, int fishquantity, double fishprice) {
super(number, fishname, fishquantity, fishprice);
}
public double getValue() {
double inventoryvalue = super.getValue();
return (inventoryvalue * 1.05);
}
}
import javax.swing.SwingUtilities;
public class Fish2 {
public static final int MAXIMUM_ITEMS = 4;
public Fish2() {}
public static void main(String[] args) {
// Create Java JFrame / GUI
SwingUtilities.invokeLater(new Runnable() {
public void run() {
InventoryGUI inventoryGUI = new InventoryGUI(new Inventory());
inventoryGUI.createDisplayGUI();
}
});
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
public class Inventory
{
public static final int MAXIMUM_ITEMS = 10;
private static Product product[] = new Fish[MAXIMUM_ITEMS];
public static void main(String args[]) {
buildInventory();
getInventory();
}
public static void buildInventory() {
product[0] = new Fish(0, "Fancy Tailed Guppy",25, 4.99);
product[1] = new Fish(1, "Huma Huma Picasso Trigger",2, 35.99);
product[2] = new Fish(2, "Black Durgeon Trigger",1, 99.99);
product[3] = new Fish(3, "Niger Trigger",2, 45.99);
product[4] = new Fish(4, "Jack Dempsey Cichlid",4, 19.99);
product[5] = new Fish(5, "Midas Cichlid",1, 69.99);
product[6] = new Fish(6, "Neon Tetra",25, 2.99);
product[7] = new Fish(7, "Convict Cichlid",2, 15.99);
product[8] = new Fish(8, "Oscar", 4, 37.99);
product[9] = new Fish(9, "Albino Cory Cat",1, 29.99);
}
public static void getInventory() {
for(int i = 0; i < product.length; i++) {
System.out.println("Number: " + product[i].getNumber());
System.out.println("Name: " + product[i].getName());
System.out.println("Quantity: " + product[i].getQuantity());
System.out.println("Price: " + product[i].getPrice());
System.out.println("Item Value: " + product[i].getQuantity() * product[i].getPrice());
System.out.printf("Restock Fee: " + (product[i].getQuantity() * product[i].getPrice()) * 0.05);
// System.out.printf("\n%s's Inventory Total including Restocking Fee is: $%5.2f.\n");
}
}
Product Product() {
return null;
}
Product[] getProduct() {
return null;
}
}
This line has been commented out because I could never get the restocking fee to display right: // System.out.printf("\n%s's Inventory Total including Restocking Fee is: $%5.2f.\n");
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
public class InventoryGUI {
private GridLayout gridLayout = new GridLayout(Inventory.MAXIMUM_ITEMS,2);
private JFrame frame = null;
private JLabel label = null;
private JTextField textField = null;
private Inventory inventory = null;
public static final int MAXIMUM_ITEMS = 4;
Product[] product = null;
private String price = "";
public InventoryGUI(Inventory inventory) {
this.inventory = inventory;
}
public void createDisplayGUI() {
// Create a JFrame container for all GUI widgets
frame = new JFrame("Inventory");
frame = new JFrame("Number");
frame = new JFrame("Name");
frame = new JFrame("Quantity");
frame = new JFrame("Price");
frame = new JFrame("Item Value");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Set up default look and feel for particular Operating System
JFrame.setDefaultLookAndFeelDecorated(true);
// Set up the content pane and components in GridLayout
Container container = frame.getContentPane();
container.setLayout(gridLayout);
// get the all the products in the inventory
product = inventory.getProduct();
// loop through all the products in the inventory and display them.
for (int i=0; i < Inventory.MAXIMUM_ITEMS; i++) {
// Define label widget
label = new JLabel(product[i].getName());
Icon logo = new ImageIcon("C:/COMPANYLOGO.jpg");
label = new JLabel(logo);
label.setToolTipText("Company Logo");
// Define textField widget
price = Double.toString (product[i].getPrice());
textField = new JTextField(price);
// add widgets to JFrame
container.add(label);
container.add(textField);
//add buttons to JFrame
JButton add = new JButton("Add");
JButton delete = new JButton("Delete");
JButton modify = new JButton("Modify");
JButton first = new JButton("First");
JButton next = new JButton("Next");
JButton previous = new JButton("Previous");
JButton last = new JButton("Last");
}
// display the frame and all widgets within
frame.pack();
frame.setVisible(true);
}
}
public class Product {
private String name = "";
private int number = 0;
private double price = 0;
private int quantity = 0;
public Product(int number, String name, int quantity, double price) {
this.number = number;
this.name = name;
this.quantity = quantity;
this.price = price;
}
public String getName() { return name; }
public int getNumber() { return number; }
public double getPrice() { return price; }
public int getQuantity() { return quantity; }
public double getValue() {
return (double) quantity * price;
}
}
Thanks to anyone who helps! I just want to pass this class with a little understanding of Java.

New Topic/Question
Reply



MultiQuote





|