I am trying to add the Delete button, save and search buttons. I have tried to call my teacher and he is absolutly no help and i have read and reread the text but still have no idea what is going on.........I have the added the add button but now i am stuck. Is there a simple way in completeing this??
Please help
• Due Date: Day 7 [Individual] forum
• 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. • Post as an attachment
I am having the same problem I developed the icon for add but I am lost this is my program I called this one my buttonframe
// Display The DVDs.
import java.text.*;
import java.util.*;
import java.awt.*;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.*;
public class ButtonFrame extends JFrame
{
private JButton nextJButton; // button with just text
private JButton prevJButton; // button with icons
private JButton lastJButton; // button with just text
private JButton firstJButton; // button with icons
private JButton addJButton; // button with icons
private JLabel logoLabel;
private JTextField space1;
private JTextField space2;
private JTextField lblArtist; // text field with set size
private JTextField txtArtist; // text field constructed with text
private JTextField lblItemNum; // text field with set size
private JTextField txtItemNum; // text field constructed with text
private JTextField lblTitle; // text field with set size
private JTextField txtTitle; // text field constructed with text
private JTextField lblQuantity; // text field with set size
private JTextField txtQuantity; // text field constructed with text
private JTextField lblUnitPrice; // text field with set size
private JTextField txtUnitPrice; // text field constructed with text
private JTextField lblRestockFee; // text field with set size
private JTextField txtRestockFee; // text field constructed with text
private JTextField lblItemValue; // text field with set size
private JTextField txtItemValue; // text field constructed with text
private JTextField lblInventoryValue; // text field with set size
private JTextField txtInventoryValue; // text field constructed with text
// Just keeping an a class variable to keep count of where I am in the array
// keeping a class variable of the myPlayer array that I passed
UsedDVD[] arrayDVDs;
private int currentArrayCounter;
private int arrayCount;
private String invTotal;
// public Image i;
// i = getImage(getDocumentBase(), "logo.gif");
// ButtonFrame adds JButtons to JFrame
public ButtonFrame(UsedDVD[] myDVDs, int totalArrayCount, String stringInventoryTotal)
{
super( "UsedDVD Inventory" );
arrayDVDs = myDVDs;
invTotal=stringInventoryTotal;
// drawImage(i,0,0);
// I am setting the local passed variable totalArrayCount
// to the class variable arrayCounter so I can see it in the setTextfields method
arrayCount = totalArrayCount;
currentArrayCounter = 0;
// Sertting the current array position to 0
setLayout( new FlowLayout() ); // set frame layout
// Load the next and previous icons
Icon logo = new ImageIcon( getClass().getResource( "logo.gif" ) );
Icon iconAdd = new ImageIcon(getClass().getResource( "add.gif" ) );
Icon iconNext = new ImageIcon( getClass().getResource( "forward.gif" ) );
Icon iconPrev = new ImageIcon( getClass().getResource( "back.gif" ) );
Icon iconLast = new ImageIcon( getClass().getResource( "last.gif" ) );
Icon iconFirst = new ImageIcon( getClass().getResource( "first.gif" ) );
logoLabel = new JLabel("",logo,SwingConstants.LEFT);
add(logoLabel);
// construct Label Fields with default text and 25 columns
space1 = new JTextField( "", 20 );
space1.setEditable( false ); // disable editing
add( space1 );
space2 = new JTextField( "", 20 );
space2.setEditable( false ); // disable editing
add( space2 );
lblItemNum = new JTextField( "Item Number", 25 );
lblItemNum.setEditable( false ); // disable editing
add( lblItemNum );
txtItemNum = new JTextField("", 25 );
add( txtItemNum ); // add txtActor to JFrame
lblArtist = new JTextField( "Actor", 25 );
lblArtist.setEditable( false ); // disable editing
add( lblArtist );
txtArtist = new JTextField("", 25 );
add( txtArtist ); // add txtActor to JFrame
lblTitle = new JTextField( "Title", 25 );
lblTitle.setEditable( false ); // disable editing
add( lblTitle );
txtTitle = new JTextField("", 25 );
add( txtTitle ); // add txtActor to JFrame
lblQuantity = new JTextField( "Quantity", 25 );
lblQuantity.setEditable( false ); // disable editing
add( lblQuantity );
txtQuantity = new JTextField("", 25 );
add( txtQuantity ); // add txtActor to JFrame
lblUnitPrice = new JTextField( "Unit Price", 25 );
lblUnitPrice.setEditable( false ); // disable editing
add( lblUnitPrice );
txtUnitPrice = new JTextField("", 25 );
add( txtUnitPrice ); // add txtUnitPrice to JFrame
lblRestockFee = new JTextField( "Restocking Fee", 25 );
lblRestockFee.setEditable( false ); // disable editing
add( lblRestockFee );
txtRestockFee = new JTextField("", 25 );
add( txtRestockFee ); // add txtActor to JFrame
lblItemValue = new JTextField( "Total Item Value", 25 );
lblItemValue.setEditable( false ); // disable editing
add( lblItemValue );
txtItemValue = new JTextField("", 25 );
add( txtItemValue ); // add txtActor to JFrame
lblInventoryValue = new JTextField( "Total Inventory Value", 25 );
lblInventoryValue.setEditable( false ); // disable editing
add( lblInventoryValue );
txtInventoryValue = new JTextField(invTotal, 25 );
add( txtInventoryValue ); // add txtActor to JFrame
// construct textfield with default text
// Create the buttons
addJButton = new JButton( "Add", iconAdd ); //button with Add
nextJButton = new JButton( "Next", iconNext ); // button with Next
prevJButton =new JButton( "Prev" , iconPrev ); // button with Prev
lastJButton = new JButton( "Last", iconLast ); // button with Last
firstJButton =new JButton( "First" , iconFirst ); // button with First
add( addJButton) ;
add( firstJButton ); // add plainJButton to JFrame
add(prevJButton);
add( nextJButton ); // add plainJButton to JFrame
add(lastJButton);
// create new ButtonHandler for button event handling
ButtonHandler handler = new ButtonHandler();
addJButton.addActionListener (handler );
firstJButton.addActionListener( handler );
prevJButton.addActionListener( handler );
nextJButton.addActionListener( handler );
lastJButton.addActionListener( handler );
// Now I am going to call SetTextFields to set the text fields
setTextFields();
} // end ButtonFrame constructor
// inner class for button event handling
private class ButtonHandler implements ActionListener
{
// handle button event
public void actionPerformed( ActionEvent event )
{
// System.out.println(event.getActionCommand());
// See which button was pressed
if (event.getActionCommand()== "Next"){
currentArrayCounter++;
}
else if (event.getActionCommand()== "Prev"){
currentArrayCounter--;
}
else if (event.getActionCommand()== "Last"){
currentArrayCounter= arrayCount-1;
}
else if (event.getActionCommand()== "First"){
currentArrayCounter = 0;
}
else if (event.getActionCommand()== "Add"){
currentArrayCounter = +1;
}
else if (event.getActionCommand()== "Delete"){
currentArrayCounter = 0;
}
setTextFields();
} // end method actionPerformed
} // end private inner class ButtonHandler
private void setTextFields ()
{
// Make sure you havent gone past the end of the array
if (currentArrayCounter == arrayCount)
{
currentArrayCounter = 0;
}
// Make sure you havent gone past the first if so, set it to the last
if (currentArrayCounter < 0)
{
currentArrayCounter = arrayCount-1;
}
// System.out.println(currentArrayCounter); // Debug statement
NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US); //Provides Locale appropriate currency format
txtArtist.setText(arrayDVDs[currentArrayCounter].getactor());
txtItemNum.setText(arrayDVDs[currentArrayCounter].getitemnumber());
txtTitle.setText(arrayDVDs[currentArrayCounter].gettitle());
txtQuantity.setText(Double.toString(arrayDVDs[currentArrayCounter].getquantity()));
txtUnitPrice.setText(Double.toString(arrayDVDs[currentArrayCounter].getunitprice()));
String stringRestockFee = n.format(arrayDVDs[currentArrayCounter].CalculateRestockFee());
txtRestockFee.setText(stringRestockFee);
txtItemValue.setText(n.format(arrayDVDs[currentArrayCounter].calculateDVDValue()));
}
} // end class ButtonFrame