Welcome to Dream.In.Code
Become a Java Expert!

Join 149,609 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,866 people online right now. Registration is fast and FREE... Join Now!




inventory part 5

 
Reply to this topicStart new topic

inventory part 5

twin2003
19 Aug, 2007 - 02:30 PM
Post #1

New D.I.C Head
*

Joined: 22 Jul, 2007
Posts: 10


My Contributions
need help with this

Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item
should display. the GUI using Java graphics classes.
• Add a company logo to the GUI using Java graphics classes.


here is what I have so far
CODE
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;



public class Inventory2
{
//main method begins execution of java application
public static void main(final String args[])
{

int i; // varialbe for looping
double total = 0; // variable for total inventory
final int dispProd = 0; // variable for actionEvents

// Instantiate a product object
final ProductAdd[] nwProduct = new ProductAdd[5];
// Instantiate objects for the array
for (i=0; i<5; i++)
{
nwProduct[0] = new ProductAdd("Paper", 101, 10, 1.00, "Box");
nwProduct[1] = new ProductAdd("Pen", 102, 10, 0.75, "Pack");
nwProduct[2] = new ProductAdd("Pencil", 103, 10, 0.50, "Pack");
nwProduct[3] = new ProductAdd("Staples", 104, 10, 1.00, "Box");
nwProduct[4] = new ProductAdd("Clip Board", 105, 10, 3.00, "Two Pack");
}



for (i=0; i<5; i++)
total += nwProduct.length; // calculate total inventory cost



final JButton firstBtn = new JButton("First"); // first button
final JButton prevBtn = new JButton("Previous"); // previous button
final JButton nextBtn = new JButton("Next"); // next button
final JButton lastBtn = new JButton("Last"); // last button
final JLabel label; // logo
final JTextArea textArea; // text area for product list
final JPanel buttonJPanel; // panel to hold buttons

//JLabel constructor for logo
Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
label = new JLabel(logo); // create logo label
label.setToolTipText("Company Logo"); // create tooltip


buttonJPanel = new JPanel(); // set up panel
buttonJPanel.setLayout( new GridLayout(1, 4)); //set layout
// add buttons to buttonPanel
buttonJPanel.add(firstBtn);
buttonJPanel.add(prevBtn);
buttonJPanel.add(nextBtn);
buttonJPanel.add(lastBtn);


textArea = new JTextArea(nwProduct[3]+"\n"); // create textArea for product display

// add total inventory value to GUI
textArea.append("\nTotal value of Inventory "+new java.text.DecimalFormat("$0.00").format(total)+"\n\n");
textArea.setEditable(false); // make text uneditable in main display
JFrame invFrame = new JFrame(); // create JFrame container
invFrame.setLayout(new BorderLayout()); // set layout
invFrame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); // add textArea to JFrame
invFrame.getContentPane().add(buttonJPanel, BorderLayout.SOUTH); // add buttons to JFrame
invFrame.getContentPane().add(label, BorderLayout.NORTH); // add logo to JFrame
invFrame.setTitle("Office Min Inventory"); // set JFrame title
invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // termination command
//invFrame.pack();
invFrame.setSize(400, 400); // set size of JPanel
invFrame.setLocationRelativeTo(null); // set screem location
invFrame.setVisible(true); // display window



// assign actionListener and actionEvent for each button
firstBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
textArea.setText(nwProduct[0]+"\n");
} // end firstBtn actionEvent

}); // end firstBtn actionListener
textArea.setText(nwProduct[4]+"n");

// prevBtn.addActionListener(new ActionListener()

// {
// public void actionPerformed(ActionEvent ae)
// {
// dispProd = (nwProduct.length+dispProd-1) % nwProduct.length;
// textArea.setText(nwProduct.display(dispProd)+"\n");
// } // end prevBtn actionEvent
// }); // end prevBtn actionListener





} // end main

} // end class Inventory2

class Product
{
protected String prodName; // name of product
protected int itmNumber; // item number
protected int units; // number of units
protected double price; // price of each unit
protected double value; // value of total units


public Product(String name, int number, int unit, double each) // Constructor for class Product
{
prodName = name;
itmNumber = number;
units = unit;
price = each;

} // end constructor

public void setProdName(String name) // method to set product name
{
prodName = name;
}

public String getProdName() // method to get product name
{
return prodName;
}

public void setItmNumber(int number) // method to set item number
{
itmNumber = number;
}

public int getItmNumber() // method to get item number
{
return itmNumber;
}

public void setUnits(int unit) // method to set number of units
{
units = unit;
}

public int getUnits() // method to get number of units
{
return units;
}

public void setPrice(double each) // method to set price
{
price = each;
}

public double getPrice() // method to get price
{
return price;
}

public double calcValue() // method to set value
{
return units * price;
}



} // end class Product



class ProductAdd extends Product
{
private String feature; // variable for added feature


public ProductAdd(String name, int number, int unit, double each, String addFeat)
{
// call to superclass Product constructor
super(name, number, unit, each);

feature = addFeat;
}// end constructor

public void setFeature(String addFeat) // method to set added feature
{
feature = addFeat;
}

public String getFeature() // method to get added feature
{
return feature;
}

public double calcValueRstk() // method to set value and add restock fee
{
return units * price * 0.05;
}

public String toString()
{
return String.format("Product: %s\nItem Number: %d\nIn Stock: %d\nPrice: $%.2f\nType: %s\nTotal Value of Stock: $%.2f\nRestock Cost: $%.2f\n\n\n",
getProdName(), getItmNumber(), getUnits(), getPrice(), getFeature(), calcValue(), calcValueRstk());
}


} // end class ProductAdd

User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Inventory Part 5
21 Aug, 2007 - 03:49 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
now that we know what your assignment is... care to tell us what the error or problem is?
User is offlineProfile CardPM
+Quote Post

twin2003
RE: Inventory Part 5
22 Aug, 2007 - 08:28 PM
Post #3

New D.I.C Head
*

Joined: 22 Jul, 2007
Posts: 10


My Contributions
thx for the reply but I figured out what i was doing wrong now i have a bigger problem this is it
QUOTE
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 will do the work I just need some guideance on where to start at my guess is to make a array for the add but i dont know and i will admit it here is what I do have so far but dont know how to do this part of the assignment any help would be nice thanks so much ...


CODE
// created by N_B on July 24,2007
  import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;



public class Inventory2
{
static int dispProd = 0; // variable for actionEvents
//main method begins execution of java application
public static void main(final String args[])
{

int i; // varialbe for looping
double total = 0; // variable for total inventory


// Instantiate a product object
final ProductAdd[] nwProduct = new ProductAdd[5];
// Instantiate objects for the array
for (i=0; i<5; i++)
{
nwProduct[0] = new ProductAdd("Paper", 101, 10, 1.00, "Box");
nwProduct[1] = new ProductAdd("Pen", 102, 10, 0.75, "Pack");
nwProduct[2] = new ProductAdd("Pencil", 103, 10, 0.50, "Pack");
nwProduct[3] = new ProductAdd("Staples", 104, 10, 1.00, "Box");
nwProduct[4] = new ProductAdd("Clip Board", 105, 10, 3.00, "Two Pack");
}



for (i=0; i<5; i++)
total += nwProduct.length; // calculate total inventory cost



final JButton firstBtn = new JButton("First"); // first button
final JButton prevBtn = new JButton("Previous"); // previous button
final JButton nextBtn = new JButton("Next"); // next button
final JButton lastBtn = new JButton("Last"); // last button
final JLabel label; // logo
final JTextArea textArea; // text area for product list
final JPanel buttonJPanel; // panel to hold buttons

//JLabel constructor for logo
Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
label = new JLabel(logo); // create logo label
label.setToolTipText("Company Logo"); // create tooltip


buttonJPanel = new JPanel(); // set up panel
buttonJPanel.setLayout( new GridLayout(1, 4)); //set layout
// add buttons to buttonPanel
buttonJPanel.add(firstBtn);
buttonJPanel.add(prevBtn);
buttonJPanel.add(nextBtn);
buttonJPanel.add(lastBtn);


textArea = new JTextArea(nwProduct[3]+"\n"); // create textArea for product display

// add total inventory value to GUI
textArea.append("\nTotal value of Inventory "+new java.text.DecimalFormat("$0.00").format(total)+"\n\n");
textArea.setEditable(false); // make text uneditable in main display
JFrame invFrame = new JFrame(); // create JFrame container
invFrame.setLayout(new BorderLayout()); // set layout
invFrame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); // add textArea to JFrame
invFrame.getContentPane().add(buttonJPanel, BorderLayout.SOUTH); // add buttons to JFrame
invFrame.getContentPane().add(label, BorderLayout.NORTH); // add logo to JFrame
invFrame.setTitle("Office Min Inventory"); // set JFrame title
invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // termination command
//invFrame.pack();
invFrame.setSize(400, 400); // set size of JPanel
invFrame.setLocationRelativeTo(null); // set screem location
invFrame.setVisible(true); // display window



// assign actionListener and actionEvent for each button
firstBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispProd = 0;
textArea.setText(nwProduct[dispProd]+"\n");

} // end firstBtn actionEvent

}); // end firstBtn actionListener

//textArea.setText(nwProduct[4]+"n");

prevBtn.addActionListener(new ActionListener()

{
public void actionPerformed(ActionEvent ae)
{
dispProd--;
if (dispProd < 0)
{
dispProd = 0;
}
//dispProd = (nwProduct.length+dispProd-1) % nwProduct.length;
textArea.setText(nwProduct[dispProd]+"\n");
} // end prevBtn actionEvent
}); // end prevBtn actionListener

lastBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispProd = nwProduct.length-1;
textArea.setText(nwProduct[dispProd]+"\n");

} // end lastBtn actionEvent

}); // end lastBtn actionListener

nextBtn.addActionListener(new ActionListener()

{
public void actionPerformed(ActionEvent ae)
{
dispProd++;
if (dispProd >= nwProduct.length)
{
dispProd = nwProduct.length-1;
}
textArea.setText(nwProduct[dispProd]+"\n");
} // end nextBtn actionEvent
}); // end nextBtn actionListener



} // end main

} // end class Inventory2

class Product
{
protected String prodName; // name of product
protected int itmNumber; // item number
protected int units; // number of units
protected double price; // price of each unit
protected double value; // value of total units


public Product(String name, int number, int unit, double each) // Constructor for class Product
{
prodName = name;
itmNumber = number;
units = unit;
price = each;

} // end constructor

public void setProdName(String name) // method to set product name
{
prodName = name;
}

public String getProdName() // method to get product name
{
return prodName;
}

public void setItmNumber(int number) // method to set item number
{
itmNumber = number;
}

public int getItmNumber() // method to get item number
{
return itmNumber;
}

public void setUnits(int unit) // method to set number of units
{
units = unit;
}

public int getUnits() // method to get number of units
{
return units;
}

public void setPrice(double each) // method to set price
{
price = each;
}

public double getPrice() // method to get price
{
return price;
}

public double calcValue() // method to set value
{
return units * price;
}



} // end class Product



class ProductAdd extends Product
{
private String feature; // variable for added feature


public ProductAdd(String name, int number, int unit, double each, String addFeat)
{
// call to superclass Product constructor
super(name, number, unit, each);

feature = addFeat;
}// end constructor

public void setFeature(String addFeat) // method to set added feature
{
feature = addFeat;
}

public String getFeature() // method to get added feature
{
return feature;
}

public double calcValueRstk() // method to set value and add restock fee
{
return units * price * 0.05;
}

public String toString()
{
return String.format("Product: %s\nItem Number: %d\nIn Stock: %d\nPrice: $%.2f\nType: %s\nTotal Value of Stock: $%.2f\nRestock Cost: $%.2f\n\n\n",
getProdName(), getItmNumber(), getUnits(), getPrice(), getFeature(), calcValue(), calcValueRstk());
}


} // end class ProductAdd



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:12AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month