0

I am going crazy from trying every thing I can think of, but i'm not gona give up I'm gona figure this out even if it kills me. lol maybe I need some sleep. lol

0

Now I am getting these error:

Exception in thread "main" java.lang.NullPointerException
at inventoryi.InventoryMain.showGUI(InventoryI.java:94)
at inventoryi.InventoryMain.main(InventoryI.java:58)
Here is the coode I have So far:

import java.awt.*; //import all java.awt
import java.awt.event.*; //import all java.awt.event
import java.util.*; //import all java.util
import javax.swing.*; //import all javax.swing
import java.text.NumberFormat; // used to format currency
 
class InventoryMain extends Frame implements ActionListener
{

    CD[] productCD;
    JTextField[] fields;
    NumberFormat nf;
    JButton jbtLogo, jbtAdd, jbtFirst, jbtPrev, jbtNext, jbtLast, jbtDelete, jbtModify;    
    JLabel label; // logo   
    JPanel buttonJPanel; // panel to hold buttons
    String nameText;
    JComboBox combo;
    JTextArea textArea;
    private int index; 
    int i; // varialbe for looping
    double total = 0; // variable for total inventory   
    static int dispProd = 0; // variable for actionEvents   
    static int disptextArea;
    static int dispIndex;
    static int deleteProd = 0;
    static int modifyProd = 0;
    
    public static void main(String[] args) 
    {
           
       
        try 
        {
            UIManager.setLookAndFeel(
                    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } 
        catch (Exception e) 
        {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
        InventoryMain test = new InventoryMain();
        test.initCD();
        test.showGUI();
        test.populateFields(0);
    }
  
   
    
    public void initCD() {
        //Create an array    
        productCD = new CD[11];
     
        //fill in the classes
        productCD[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722");
        productCD[1] = new CD( 2, "Pantera" , 20.00, 10, "00263");
        productCD[2] = new CD( 3, "Ozzy" , 15.00, 10, "00142");
        productCD[3] = new CD( 4, "Soulfly" , 18.00, 10, "00553");
        productCD[4] = new CD( 5, "Down", 24.00, 10, "00789");
        productCD[5] = new CD( 6, "God Forbid" , 10.00, 10, "00712");
        productCD[6] = new CD( 7, "Black Label Society" , 16.00, 10, "00458" );
        productCD[7] = new CD( 8, "Saint Vitus" , 15.00, 10, "00889");
        productCD[8] = new CD( 9, "Clearlight" , 15.00, 10, "00897");
        productCD[9] = new CD( 10, "Testament" , 15.00, 10, "00656");        
        
      //Sort elements in array in alphabetical order by product name
       //    product[0].sortItems(product);
      
     
    }
     
     
        
    private void showGUI() {
        JLabel l;
        JButton b;
        fields = new JTextField[11];
        combo = new JComboBox();
        for(int j = 0; j < productCD.length; j++)
        combo.addItem(productCD[j].getName());
        combo.addActionListener(this);
          Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
        label = new JLabel(logo); // create logo label
        label.setToolTipText("Company Logo"); // create tooltip
            textArea = new JTextArea(productCD[3] + "\n"); // create textArea for
                                                        // product display
        JFrame f = new JFrame("CD Inventory");
        Container cp = f.getContentPane();
        cp.setLayout(new GridBagLayout());
        cp.setBackground(UIManager.getColor("control"));
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = 0;
        c.gridy = GridBagConstraints.RELATIVE;
        c.gridwidth = 1;
        c.gridheight = 1;
        c.insets = new Insets(2, 2, 2, 2);
        c.anchor = GridBagConstraints.EAST;
        cp.add(l = new JLabel("Item Number:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('a');
        cp.add(l = new JLabel("Item Name:", SwingConstants.CENTER), c);    l.setDisplayedMnemonic('b');
        cp.add(l = new JLabel("Number of Units in Stock:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('c');
        cp.add(l = new JLabel("Price per Unit: $", SwingConstants.CENTER), c);       l.setDisplayedMnemonic('d');
        cp.add(l = new JLabel("Total cost of This Item: $", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('e');
        cp.add(l = new JLabel("Total Value of All Merchandise in Inventory: $",
                               SwingConstants.CENTER), c);   l.setDisplayedMnemonic('f');
        cp.add(l = new JLabel("Item Code:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('g');
        cp.add(l = new JLabel("Product Restocking Fee: $", SwingConstants.CENTER), c);  l.setDisplayedMnemonic('h');
        cp.add(combo, c);
        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 1.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.CENTER;
        cp.add(fields[0] = new JTextField(), c);
        fields[0].setFocusAccelerator('a');
        c.gridx = 1;
        c.gridy = GridBagConstraints.RELATIVE;
        cp.add(fields[1] = new JTextField(), c);         fields[1].setFocusAccelerator('b');
        cp.add(fields[2] = new JTextField(), c);         fields[2].setFocusAccelerator('c');
        cp.add(fields[3] = new JTextField(), c);         fields[3].setFocusAccelerator('d');
        cp.add(fields[4] = new JTextField(), c);         fields[4].setFocusAccelerator('e');
        cp.add(fields[5] = new JTextField(), c);         fields[5].setFocusAccelerator('f');
        cp.add(fields[6] = new JTextField(), c);         fields[6].setFocusAccelerator('g');
        cp.add(fields[7] = new JTextField(), c);         fields[7].setFocusAccelerator('h');
        cp.add(fields[8] = new JTextField(), c);         fields[8].setFocusAccelerator('i');
        cp.add(fields[9] = new JTextField(), c);         fields[9].setFocusAccelerator('j');
        cp.add(fields[10] = new JTextField(), c);       fields[10].setFocusAccelerator('k');
        c.weightx = 0.0;
        c.fill = GridBagConstraints.NONE;
        
        jbtAdd = new JButton("Add");      
        jbtFirst = new JButton("First");        
        jbtPrev = new JButton("Previous");       
        jbtNext = new JButton("Next");       
        jbtLast = new JButton("Last");        
        jbtDelete = new JButton("Delete");       
        jbtModify = new JButton("Modify");
        jbtLogo = new JButton("Logo");
        ImageIcon Logo = new ImageIcon("logo.gif"); //initializing picture for logo Jbutton
        f.getContentPane().add(this.jbtLogo); //add logoBtn to content pane
        this.jbtLogo.setBounds(0, 0, 75, 75); //set logoBtn's size
        this.jbtLogo.setBorderPainted(false); //turn border off for logoBtn
        cp.add(jbtAdd, c);
        cp.add(jbtFirst, c);
        cp.add(jbtPrev, c);
        cp.add(jbtNext, c);
        cp.add(jbtLast, c);
        cp.add(jbtDelete, c);
        cp.add(jbtModify, c);
        cp.add(jbtLogo, c);
        f.pack();
       f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
           
// assign actionListener and actionEvent for each button
        jbtAdd.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = - 0;
                
                populateFields(dispProd);
                
            } // end addBtn actionEvent
            
        }); // end addBtn actionListener
        jbtFirst.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = 0;
                populateFields(dispProd);
 
            } // end firstBtn actionEvent
 
        }); // end firstBtn actionListener
 
 
        jbtPrev.addActionListener(new ActionListener()
 
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd--;
                if (dispProd < 0)
                {
                    dispProd = productCD.length - 1;
                }
                populateFields(dispProd); 
               
            } // end prevBtn actionEvent
        }); // end prevBtn actionListener
 
        jbtLast.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = productCD.length - 1;
               populateFields(dispProd); 
           
            } // end lastBtn actionEvent
 
        }); // end lastBtn actionListener
 
        jbtNext.addActionListener(new ActionListener()
 
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd++;
                if (dispProd > productCD.length - 1)
                {
                    dispProd = 0;
                }
               populateFields(dispProd);
            } // end nextBtn actionEvent
        }); // end nextBtn actionListener
       
         jbtDelete.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            dispProd = 0;
            
            } // end deleteBtn actionEvent
         }); // end deleteBtn actionListener
         
         jbtModify.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            for(int j = 0; j < productCD.length; j++)
            populateFields(dispProd);
            
            } // end modifyBtn actionEvent
         }); // end modifyBtn actionListener
    }
    // event handler for combo box
    public void actionPerformed(ActionEvent e)
    {        
        if(e.getSource() == combo)
        {
               
            System.out.println("Selected option: " + combo.getSelectedIndex() );
        }
    }
    private void populateFields(int index) {
        CD cd = productCD[index];
        fields[0].setText(Long.toString(cd.getNumberCode()));
        fields[1].setText(cd.getName());
        fields[2].setText(Long.toString(cd.getUnits()));
        fields[3].setText(Double.toString(cd.getPrice()));
        fields[4].setText(Double.toString(cd.getSum()));
        fields[5].setText(Double.toString(cd.totalAllInventory(productCD)));
        fields[6].setText(cd.getCode());
        fields[7].setText(Double.toString(cd.getSum()*.05));        
    }
}
class CD {
      
    int itemNumber;
    String name;
    String text;
    int units;
    int item;
    double price;
    String itemCode; 
    String command;
    public CD(int n, String name, double price, int units, String itemCo) {
        itemNumber = n;
        this.name = name;
        this.price = price;
        this.units = units;
        itemCode = itemCo;
    }

    public int getNumberCode() { return itemNumber; }    
    public String getName() { return name; }
    public int getUnits() { return units; }
    public double getPrice() { return price; }
    public double getSum() { return units*price; }
    public String getCode() { return itemCode; }
    public String getActionnCommand() {return command; }
    public int addItem() {return item; }
    public double totalAllInventory(CD[] cds) {
        double total = 0;
        for(int j = 0; j < cds.length; j++)
            total += cds[j].getSum();
        return total;
    }
}

public class InventoryI {
        
    String productnumber;
 
    String name;
 
    String Text;
        
        String fields;
        
        int numberofunits;
 
    double priceperunit;
        
        String itemcode; 
        
       
        

    // Create a new instance of Inventory
    // main constructor for the class
    public InventoryI(String Item_Number, String Item_Name, int Items_in_Stock,
            double Item_Price, String Item_Code) {
        productnumber = Item_Number;
        name = Item_Name;
        numberofunits = Items_in_Stock;
        priceperunit = Item_Price;
                itemcode = Item_Code;
                
                
       
    }        
 
    public void setItemName(String Item_Name) {
    // sets the items name

        name = Item_Name;
    }
 
    public void setItemCode(String Item_Code) {
    // sets the items name

        itemcode = Item_Code;
    }
        public void setItemNumber(String Item_Number) { // Sets the Product =Number
    // for the item
 
        productnumber = Item_Number;
    }
 
    public void setItemsInStock(int Items_in_Stock) { // sets the =number of
    // units in stock
 
        numberofunits = Items_in_Stock;
    }
 
    public void setItemPrice(double Item_Price) { // sets the price of =the
    // item
        priceperunit = Item_Price;
     
    }
       
        public String getItemName() { // returns the Product Name of this item
        return name;
    }
 
     public String getItemCode() { // returns the Product Name of this item
        return itemcode;
        }
         
        public String getItemNumber() { // returns the Product Number of the =item
 
        return productnumber;
    }
 
    public int getItemsInStock() { // returns how many units are in stock
        return numberofunits;
    }
 
    public double getItemPrice() { // returns the price of the item
        return priceperunit;
    }
 
    public double getInventoryIValue() { // returns the total value of =the stock
    // for this item
        return priceperunit * numberofunits;
    }
        
    public static double getTotalValueOfAllInventory(InventoryI [] inv) {
    
            double tot = 0.0;
        
        for(int i = 0; i < inv.length; i++)   
                
            tot += inv[i].getInventoryIValue();
        
        return tot;
        
    }
    
    public static InventoryI[] sort(InventoryI [] inventory)
    {
        InventoryI temp[] = new InventoryI[1];
         
        //sorting the array using Bubble Sort
        for(int j = 0; j < inventory.length - 1; j++)
        {
         
            for(int k = 0; k < inventory.length - 1; k++)
            {
         
                if(inventory[k].getItemName().compareToIgnoreCase(inventory[k+1].getItemName()) > 0)
                {
         
                    temp[0] = inventory[k];
                    inventory[k] = inventory[k+1];
                    inventory[k+1] = temp[0];
         
                }//end if
         
            }//end for loop
         
        }//end for loop

        
        return inventory;
                
    }
    
    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        
                
        sb.append("CD Title:      \t").append(name).append("\n");
                sb.append("Item Code:      \t").append(itemcode).append("\n");
        sb.append("Item #:           \t").append(productnumber).append("\n");
        sb.append("Number in stock:\t").append(numberofunits).append("\n");
        sb.append("Price:          \t").append(String.format("$%.2f%n", priceperunit));
        sb.append("Inventory Value:\t").append(String.format("$%.2f%n", this.getInventoryIValue()));
 
        return sb.toString();
                
                
    }
    
    
}

I've got two day to understand and finish this program and I am lost and scared of failing my class. I have read so many tutorials that I wake up talking in java code. lol
I'm sorry for venting but I needed it. I want to thank you guys forhelping me understand the parts that I didn. I wish you guys were my instructor for this class, I would probably be a java pro.

0

Working version

public void initCD() {
        //Create an array    
        productCD = new CD[10];

        //fill in the classes
        productCD[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722");
        productCD[1] = new CD( 2, "Pantera" , 20.00, 10, "00263");
        productCD[2] = new CD( 3, "Ozzy" , 15.00, 10, "00142");
        productCD[3] = new CD( 4, "Soulfly" , 18.00, 10, "00553");
        productCD[4] = new CD( 5, "Down", 24.00, 10, "00789");
        productCD[5] = new CD( 6, "God Forbid" , 10.00, 10, "00712");
        productCD[6] = new CD( 7, "Black Label Society" , 16.00, 10, "00458" );
        productCD[7] = new CD( 8, "Saint Vitus" , 15.00, 10, "00889");
        productCD[8] = new CD( 9, "Clearlight" , 15.00, 10, "00897");
        productCD[9] = new CD( 10, "Testament" , 15.00, 10, "00656");

not working version

public void initCD() {
        //Create an array    
        productCD = new CD[11];
        //fill in the classes
        productCD[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722");
        productCD[1] = new CD( 2, "Pantera" , 20.00, 10, "00263");
        productCD[2] = new CD( 3, "Ozzy" , 15.00, 10, "00142");
        productCD[3] = new CD( 4, "Soulfly" , 18.00, 10, "00553");
        productCD[4] = new CD( 5, "Down", 24.00, 10, "00789");
        productCD[5] = new CD( 6, "God Forbid" , 10.00, 10, "00712");
        productCD[6] = new CD( 7, "Black Label Society" , 16.00, 10, "00458" );
        productCD[7] = new CD( 8, "Saint Vitus" , 15.00, 10, "00889");
        productCD[8] = new CD( 9, "Clearlight" , 15.00, 10, "00897");
        productCD[9] = new CD( 10, "Testament" , 15.00, 10, "00656");

Think about it, why is it not working?

An consider following possible changes
in InventoryMain.java

public void initCD() {
        //Create an array    
        productCD = new CD[20];
     
        //fill in the classes
        productCD[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722");
        productCD[1] = new CD( 2, "Pantera" , 20.00, 10, "00263");
        productCD[2] = new CD( 3, "Ozzy" , 15.00, 10, "00142");
        productCD[3] = new CD( 4, "Soulfly" , 18.00, 10, "00553");
        productCD[4] = new CD( 5, "Down", 24.00, 10, "00789");
        productCD[5] = new CD( 6, "God Forbid" , 10.00, 10, "00712");
        productCD[6] = new CD( 7, "Black Label Society" , 16.00, 10, "00458" );
        productCD[7] = new CD( 8, "Saint Vitus" , 15.00, 10, "00889");
        productCD[8] = new CD( 9, "Clearlight" , 15.00, 10, "00897");
        productCD[9] = new CD( 10, "Testament" , 15.00, 10, "00656"); 
        	
        for(int i = 10; i < productCD.length; i++)
        {
        	productCD[i] = new CD();
        }     
    }

and in CD.java

public CD() {}
0

Okay, I got the add button to work. all the buttons work except the delete, modify, and the save and search buttons which i have not added yet. here is the code:

import java.awt.*; //import all java.awt
import java.awt.event.*; //import all java.awt.event
import java.util.*; //import all java.util
import javax.swing.*; //import all javax.swing
import java.text.NumberFormat; // used to format currency
 
class InventoryMain extends Frame implements ActionListener
{

    CD[] productCD;
    JTextField[] fields;
    NumberFormat nf;
    JButton jbtLogo, jbtAdd, jbtFirst, jbtPrev, jbtNext, jbtLast, jbtDelete, jbtModify;    
    JLabel label; // logo   
    JPanel buttonJPanel; // panel to hold buttons
    String nameText;
    JComboBox combo;
    JTextArea textArea;
    private int index; 
    int i; // varialbe for looping
    double total = 0; // variable for total inventory   
    static int dispProd = 0; // variable for actionEvents   
    static int disptextArea;
    static int dispIndex;
    
    
    public static void main(String[] args) 
    {
           
       
        try 
        {
            UIManager.setLookAndFeel(
                    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } 
        catch (Exception e) 
        {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
        InventoryMain test = new InventoryMain();
        test.initCD();
        test.showGUI();
        test.populateFields(0);
    }
  
   
    
    public void initCD() {
        //Create an array    
        productCD = new CD[20];
     
        //fill in the classes
        productCD[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722");
        productCD[1] = new CD( 2, "Pantera" , 20.00, 10, "00263");
        productCD[2] = new CD( 3, "Ozzy" , 15.00, 10, "00142");
        productCD[3] = new CD( 4, "Soulfly" , 18.00, 10, "00553");
        productCD[4] = new CD( 5, "Down", 24.00, 10, "00789");
        productCD[5] = new CD( 6, "God Forbid" , 10.00, 10, "00712");
        productCD[6] = new CD( 7, "Black Label Society" , 16.00, 10, "00458" );
        productCD[7] = new CD( 8, "Saint Vitus" , 15.00, 10, "00889");
        productCD[8] = new CD( 9, "Clearlight" , 15.00, 10, "00897");
        productCD[9] = new CD( 10, "Testament" , 15.00, 10, "00656");        
        
     for(int i = 10; i < productCD.length; i++)
        {
            productCD[i] = new CD();
        }     
    }
     
     
        
    private void showGUI() {
        JLabel l;
        JButton b;
        fields = new JTextField[11];
        combo = new JComboBox();
        for(int j = 0; j < productCD.length; j++)
        combo.addItem(productCD[j].getName());
        combo.addActionListener(this);
          Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
        label = new JLabel(logo); // create logo label
        label.setToolTipText("Company Logo"); // create tooltip
            textArea = new JTextArea(productCD[3] + "\n"); // create textArea for
                                                        // product display
        JFrame f = new JFrame("CD Inventory");
        Container cp = f.getContentPane();
        cp.setLayout(new GridBagLayout());
        cp.setBackground(UIManager.getColor("control"));
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = 0;
        c.gridy = GridBagConstraints.RELATIVE;
        c.gridwidth = 1;
        c.gridheight = 1;
        c.insets = new Insets(2, 2, 2, 2);
        c.anchor = GridBagConstraints.EAST;
        cp.add(l = new JLabel("Item Number:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('a');
        cp.add(l = new JLabel("Item Name:", SwingConstants.CENTER), c);    l.setDisplayedMnemonic('b');
        cp.add(l = new JLabel("Number of Units in Stock:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('c');
        cp.add(l = new JLabel("Price per Unit: $", SwingConstants.CENTER), c);       l.setDisplayedMnemonic('d');
        cp.add(l = new JLabel("Total cost of This Item: $", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('e');
        cp.add(l = new JLabel("Total Value of All Merchandise in Inventory: $",
                               SwingConstants.CENTER), c);   l.setDisplayedMnemonic('f');
        cp.add(l = new JLabel("Item Code:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('g');
        cp.add(l = new JLabel("Product Restocking Fee: $", SwingConstants.CENTER), c);  l.setDisplayedMnemonic('h');
        cp.add(combo, c);
        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 1.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.CENTER;
        cp.add(fields[0] = new JTextField(), c);
        fields[0].setFocusAccelerator('a');
        c.gridx = 1;
        c.gridy = GridBagConstraints.RELATIVE;
        cp.add(fields[1] = new JTextField(), c);         fields[1].setFocusAccelerator('b');
        cp.add(fields[2] = new JTextField(), c);         fields[2].setFocusAccelerator('c');
        cp.add(fields[3] = new JTextField(), c);         fields[3].setFocusAccelerator('d');
        cp.add(fields[4] = new JTextField(), c);         fields[4].setFocusAccelerator('e');
        cp.add(fields[5] = new JTextField(), c);         fields[5].setFocusAccelerator('f');
        cp.add(fields[6] = new JTextField(), c);         fields[6].setFocusAccelerator('g');
        cp.add(fields[7] = new JTextField(), c);         fields[7].setFocusAccelerator('h');
        cp.add(fields[8] = new JTextField(), c);         fields[8].setFocusAccelerator('i');
        cp.add(fields[9] = new JTextField(), c);         fields[9].setFocusAccelerator('j');
        cp.add(fields[10] = new JTextField(), c);       fields[10].setFocusAccelerator('k');
        c.weightx = 0.0;
        c.fill = GridBagConstraints.NONE;
        
        jbtAdd = new JButton("Add");      
        jbtFirst = new JButton("First");        
        jbtPrev = new JButton("Previous");       
        jbtNext = new JButton("Next");       
        jbtLast = new JButton("Last");        
        jbtDelete = new JButton("Delete");       
        jbtModify = new JButton("Modify");
        jbtLogo = new JButton("Logo");
        ImageIcon Logo = new ImageIcon("logo.gif"); //initializing picture for logo Jbutton
        f.getContentPane().add(this.jbtLogo); //add logoBtn to content pane
        this.jbtLogo.setBounds(0, 0, 75, 75); //set logoBtn's size
        this.jbtLogo.setBorderPainted(false); //turn border off for logoBtn
        cp.add(jbtAdd, c);
        cp.add(jbtFirst, c);
        cp.add(jbtPrev, c);
        cp.add(jbtNext, c);
        cp.add(jbtLast, c);
        cp.add(jbtDelete, c);
        cp.add(jbtModify, c);
        cp.add(jbtLogo, c);
        f.pack();
       f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
           
// assign actionListener and actionEvent for each button
        jbtAdd.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = 11;
                
                populateFields(dispProd);
                
            } // end addBtn actionEvent
            
        }); // end addBtn actionListener
        jbtFirst.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = 0;
                populateFields(dispProd);
 
            } // end firstBtn actionEvent
 
        }); // end firstBtn actionListener
 
 
        jbtPrev.addActionListener(new ActionListener()
 
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd--;
                if (dispProd < 0)
                {
                    dispProd = productCD.length - 1;
                }
                populateFields(dispProd); 
               
            } // end prevBtn actionEvent
        }); // end prevBtn actionListener
 
        jbtLast.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = productCD.length - 1;
               populateFields(dispProd); 
           
            } // end lastBtn actionEvent
 
        }); // end lastBtn actionListener
 
        jbtNext.addActionListener(new ActionListener()
 
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd++;
                if (dispProd > productCD.length - 1)
                {
                    dispProd = 0;
                }
               populateFields(dispProd);
            } // end nextBtn actionEvent
        }); // end nextBtn actionListener
       
         jbtDelete.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            dispProd = 0;
            
            } // end deleteBtn actionEvent
         }); // end deleteBtn actionListener
         
         jbtModify.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            for(int j = 0; j < productCD.length; j++)
            populateFields(dispProd);
            
            } // end modifyBtn actionEvent
         }); // end modifyBtn actionListener
    }
    // event handler for combo box
    public void actionPerformed(ActionEvent e)
    {        
        if(e.getSource() == combo)
        {
               
            System.out.println("Selected option: " + combo.getSelectedIndex() );
        }
    }
    private void populateFields(int index) {
        CD cd = productCD[index];
        fields[0].setText(Long.toString(cd.getNumberCode()));
        fields[1].setText(cd.getName());
        fields[2].setText(Long.toString(cd.getUnits()));
        fields[3].setText(Double.toString(cd.getPrice()));
        fields[4].setText(Double.toString(cd.getSum()));
        fields[5].setText(Double.toString(cd.totalAllInventory(productCD)));
        fields[6].setText(cd.getCode());
        fields[7].setText(Double.toString(cd.getSum()*.05));        
    }
}
class CD {
    public CD() {}
      
    int itemNumber;
    String name;
    String text;
    int units;
    int item;
    double price;
    String itemCode; 
    String command;
    public CD(int n, String name, double price, int units, String itemCo) {
        itemNumber = n;
        this.name = name;
        this.price = price;
        this.units = units;
        itemCode = itemCo;
    }

    public int getNumberCode() { return itemNumber; }    
    public String getName() { return name; }
    public int getUnits() { return units; }
    public double getPrice() { return price; }
    public double getSum() { return units*price; }
    public String getCode() { return itemCode; }
    public String getActionnCommand() {return command; }
    public int addItem() {return item; }
    public double totalAllInventory(CD[] cds) {
        double total = 0;
        for(int j = 0; j < cds.length; j++)
            total += cds[j].getSum();
        return total;
    }
}

public class InventoryI {
        
    String productnumber;
 
    String name;
 
    String Text;
        
        String fields;
        
        int numberofunits;
 
    double priceperunit;
        
        String itemcode; 
        
       
        

    // Create a new instance of Inventory
    // main constructor for the class
    public InventoryI(String Item_Number, String Item_Name, int Items_in_Stock,
            double Item_Price, String Item_Code) {
        productnumber = Item_Number;
        name = Item_Name;
        numberofunits = Items_in_Stock;
        priceperunit = Item_Price;
                itemcode = Item_Code;
                
                
       
    }        
 
    public void setItemName(String Item_Name) {
    // sets the items name

        name = Item_Name;
    }
 
    public void setItemCode(String Item_Code) {
    // sets the items name

        itemcode = Item_Code;
    }
        public void setItemNumber(String Item_Number) { // Sets the Product =Number
    // for the item
 
        productnumber = Item_Number;
    }
 
    public void setItemsInStock(int Items_in_Stock) { // sets the =number of
    // units in stock
 
        numberofunits = Items_in_Stock;
    }
 
    public void setItemPrice(double Item_Price) { // sets the price of =the
    // item
        priceperunit = Item_Price;
     
    }
       
        public String getItemName() { // returns the Product Name of this item
        return name;
    }
 
     public String getItemCode() { // returns the Product Name of this item
        return itemcode;
        }
         
        public String getItemNumber() { // returns the Product Number of the =item
 
        return productnumber;
    }
 
    public int getItemsInStock() { // returns how many units are in stock
        return numberofunits;
    }
 
    public double getItemPrice() { // returns the price of the item
        return priceperunit;
    }
 
    public double getInventoryIValue() { // returns the total value of =the stock
    // for this item
        return priceperunit * numberofunits;
    }
        
    public static double getTotalValueOfAllInventory(InventoryI [] inv) {
    
            double tot = 0.0;
        
        for(int i = 0; i < inv.length; i++)   
                
            tot += inv[i].getInventoryIValue();
        
        return tot;
        
    }
    
    public static InventoryI[] sort(InventoryI [] inventory)
    {
        InventoryI temp[] = new InventoryI[1];
         
        //sorting the array using Bubble Sort
        for(int j = 0; j < inventory.length - 1; j++)
        {
         
            for(int k = 0; k < inventory.length - 1; k++)
            {
         
                if(inventory[k].getItemName().compareToIgnoreCase(inventory[k+1].getItemName()) > 0)
                {
         
                    temp[0] = inventory[k];
                    inventory[k] = inventory[k+1];
                    inventory[k+1] = temp[0];
         
                }//end if
         
            }//end for loop
         
        }//end for loop

        
        return inventory;
                
    }
    
    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        
                
        sb.append("CD Title:      \t").append(name).append("\n");
                sb.append("Item Code:      \t").append(itemcode).append("\n");
        sb.append("Item #:           \t").append(productnumber).append("\n");
        sb.append("Number in stock:\t").append(numberofunits).append("\n");
        sb.append("Price:          \t").append(String.format("$%.2f%n", priceperunit));
        sb.append("Inventory Value:\t").append(String.format("$%.2f%n", this.getInventoryIValue()));
 
        return sb.toString();
                
                
    }
    
    
}

I feel like I'm never going to finish this on time. I wish my class instructor was as helpfull as you. thanks.

0

Can some one give me some advisee as to what I am doing wrong. I knoow its going to be something simple that I'm overlooking, ive been workinng onn this for the last 4 days and I cant think strait anymore. thanks.

0

This your last post

Can some one give me some advisee as to what I am doing wrong. I knoow its going to be something simple that I'm overlooking, ive been workinng onn this for the last 4 days and I cant think strait anymore. thanks.

and this is post befor it

Okay, I got the add button to work. all the buttons work except the delete, modify, and the save and search buttons which i have not added yet. here is the code:

You did not provide any info on what is happening, so we have no idea what can be wrong...

Anyway what is difference between add and save ?

0

You did not provide any info on what is happening, so we have no idea what can be wrong...

I'm sorry, I cant think strait from looking at a computer screen for 20 hours.

the save button needs to save the inventory to a C:\data\inventory.dat file.

0

Here is my code again, im not reseaving any errors but the delete, modify buttons do not do what they are needed to do, and the save and search buttons which i have not added yet. here is the code:

import java.awt.*; //import all java.awt
import java.awt.event.*; //import all java.awt.event
import java.util.*; //import all java.util
import javax.swing.*; //import all javax.swing
import java.text.NumberFormat; // used to format currency
 
class InventoryMain extends Frame implements ActionListener
{

    CD[] productCD;
    JTextField[] fields;
    NumberFormat nf;
    JButton jbtLogo, jbtAdd, jbtFirst, jbtPrev, jbtNext, jbtLast, jbtDelete, jbtModify;    
    JLabel label; // logo   
    JPanel buttonJPanel; // panel to hold buttons
    String nameText;
    JComboBox combo;
    JTextArea textArea;
    private int index; 
    int i; // varialbe for looping
    double total = 0; // variable for total inventory   
    static int dispProd = 0; // variable for actionEvents   
    static int disptextArea;
    static int dispIndex;
    
    
    public static void main(String[] args) 
    {
           
       
        try 
        {
            UIManager.setLookAndFeel(
                    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } 
        catch (Exception e) 
        {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
        InventoryMain test = new InventoryMain();
        test.initCD();
        test.showGUI();
        test.populateFields(0);
    }
  
   
    
    public void initCD() {
        //Create an array    
        productCD = new CD[20];
     
        //fill in the classes
        productCD[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722");
        productCD[1] = new CD( 2, "Pantera" , 20.00, 10, "00263");
        productCD[2] = new CD( 3, "Ozzy" , 15.00, 10, "00142");
        productCD[3] = new CD( 4, "Soulfly" , 18.00, 10, "00553");
        productCD[4] = new CD( 5, "Down", 24.00, 10, "00789");
        productCD[5] = new CD( 6, "God Forbid" , 10.00, 10, "00712");
        productCD[6] = new CD( 7, "Black Label Society" , 16.00, 10, "00458" );
        productCD[7] = new CD( 8, "Saint Vitus" , 15.00, 10, "00889");
        productCD[8] = new CD( 9, "Clearlight" , 15.00, 10, "00897");
        productCD[9] = new CD( 10, "Testament" , 15.00, 10, "00656");        
        
     for(int i = 10; i < productCD.length; i++)
        {
            productCD[i] = new CD();
        }     
    }
     
     
        
    private void showGUI() {
        JLabel l;
        JButton b;
        fields = new JTextField[11];
        combo = new JComboBox();
        for(int j = 0; j < productCD.length; j++)
        combo.addItem(productCD[j].getName());
        combo.addActionListener(this);
          Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
        label = new JLabel(logo); // create logo label
        label.setToolTipText("Company Logo"); // create tooltip
            textArea = new JTextArea(productCD[3] + "\n"); // create textArea for
                                                        // product display
        JFrame f = new JFrame("CD Inventory");
        Container cp = f.getContentPane();
        cp.setLayout(new GridBagLayout());
        cp.setBackground(UIManager.getColor("control"));
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = 0;
        c.gridy = GridBagConstraints.RELATIVE;
        c.gridwidth = 1;
        c.gridheight = 1;
        c.insets = new Insets(2, 2, 2, 2);
        c.anchor = GridBagConstraints.EAST;
        cp.add(l = new JLabel("Item Number:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('a');
        cp.add(l = new JLabel("Item Name:", SwingConstants.CENTER), c);    l.setDisplayedMnemonic('b');
        cp.add(l = new JLabel("Number of Units in Stock:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('c');
        cp.add(l = new JLabel("Price per Unit: $", SwingConstants.CENTER), c);       l.setDisplayedMnemonic('d');
        cp.add(l = new JLabel("Total cost of This Item: $", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('e');
        cp.add(l = new JLabel("Total Value of All Merchandise in Inventory: $",
                               SwingConstants.CENTER), c);   l.setDisplayedMnemonic('f');
        cp.add(l = new JLabel("Item Code:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('g');
        cp.add(l = new JLabel("Product Restocking Fee: $", SwingConstants.CENTER), c);  l.setDisplayedMnemonic('h');
        cp.add(combo, c);
        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 1.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.CENTER;
        cp.add(fields[0] = new JTextField(), c);
        fields[0].setFocusAccelerator('a');
        c.gridx = 1;
        c.gridy = GridBagConstraints.RELATIVE;
        cp.add(fields[1] = new JTextField(), c);         fields[1].setFocusAccelerator('b');
        cp.add(fields[2] = new JTextField(), c);         fields[2].setFocusAccelerator('c');
        cp.add(fields[3] = new JTextField(), c);         fields[3].setFocusAccelerator('d');
        cp.add(fields[4] = new JTextField(), c);         fields[4].setFocusAccelerator('e');
        cp.add(fields[5] = new JTextField(), c);         fields[5].setFocusAccelerator('f');
        cp.add(fields[6] = new JTextField(), c);         fields[6].setFocusAccelerator('g');
        cp.add(fields[7] = new JTextField(), c);         fields[7].setFocusAccelerator('h');
        cp.add(fields[8] = new JTextField(), c);         fields[8].setFocusAccelerator('i');
        cp.add(fields[9] = new JTextField(), c);         fields[9].setFocusAccelerator('j');
        cp.add(fields[10] = new JTextField(), c);       fields[10].setFocusAccelerator('k');
        c.weightx = 0.0;
        c.fill = GridBagConstraints.NONE;
        
        jbtAdd = new JButton("Add");      
        jbtFirst = new JButton("First");        
        jbtPrev = new JButton("Previous");       
        jbtNext = new JButton("Next");       
        jbtLast = new JButton("Last");        
        jbtDelete = new JButton("Delete");       
        jbtModify = new JButton("Modify");
        jbtLogo = new JButton("Logo");
        ImageIcon Logo = new ImageIcon("logo.gif"); //initializing picture for logo Jbutton
        f.getContentPane().add(this.jbtLogo); //add logoBtn to content pane
        this.jbtLogo.setBounds(0, 0, 75, 75); //set logoBtn's size
        this.jbtLogo.setBorderPainted(false); //turn border off for logoBtn
        cp.add(jbtAdd, c);
        cp.add(jbtFirst, c);
        cp.add(jbtPrev, c);
        cp.add(jbtNext, c);
        cp.add(jbtLast, c);
        cp.add(jbtDelete, c);
        cp.add(jbtModify, c);
        cp.add(jbtLogo, c);
        f.pack();
       f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
           
// assign actionListener and actionEvent for each button
        jbtAdd.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = 11;
                
                populateFields(dispProd);
                
            } // end addBtn actionEvent
            
        }); // end addBtn actionListener
        jbtFirst.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = 0;
                populateFields(dispProd);
 
            } // end firstBtn actionEvent
 
        }); // end firstBtn actionListener
 
 
        jbtPrev.addActionListener(new ActionListener()
 
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd--;
                if (dispProd < 0)
                {
                    dispProd = productCD.length - 1;
                }
                populateFields(dispProd); 
               
            } // end prevBtn actionEvent
        }); // end prevBtn actionListener
 
        jbtLast.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = productCD.length - 1;
               populateFields(dispProd); 
           
            } // end lastBtn actionEvent
 
        }); // end lastBtn actionListener
 
        jbtNext.addActionListener(new ActionListener()
 
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd++;
                if (dispProd > productCD.length - 1)
                {
                    dispProd = 0;
                }
               populateFields(dispProd);
            } // end nextBtn actionEvent
        }); // end nextBtn actionListener
       
         jbtDelete.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            dispProd = 0;
            
            } // end deleteBtn actionEvent
         }); // end deleteBtn actionListener
         
         jbtModify.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            for(int j = 0; j < productCD.length; j++)
            populateFields(dispProd);
            
            } // end modifyBtn actionEvent
         }); // end modifyBtn actionListener
    }
    // event handler for combo box
    public void actionPerformed(ActionEvent e)
    {        
        if(e.getSource() == combo)
        {
               
            System.out.println("Selected option: " + combo.getSelectedIndex() );
        }
    }
    private void populateFields(int index) {
        CD cd = productCD[index];
        fields[0].setText(Long.toString(cd.getNumberCode()));
        fields[1].setText(cd.getName());
        fields[2].setText(Long.toString(cd.getUnits()));
        fields[3].setText(Double.toString(cd.getPrice()));
        fields[4].setText(Double.toString(cd.getSum()));
        fields[5].setText(Double.toString(cd.totalAllInventory(productCD)));
        fields[6].setText(cd.getCode());
        fields[7].setText(Double.toString(cd.getSum()*.05));        
    }
}
class CD {
    public CD() {}
      
    int itemNumber;
    String name;
    String text;
    int units;
    int item;
    double price;
    String itemCode; 
    String command;
    public CD(int n, String name, double price, int units, String itemCo) {
        itemNumber = n;
        this.name = name;
        this.price = price;
        this.units = units;
        itemCode = itemCo;
    }

    public int getNumberCode() { return itemNumber; }    
    public String getName() { return name; }
    public int getUnits() { return units; }
    public double getPrice() { return price; }
    public double getSum() { return units*price; }
    public String getCode() { return itemCode; }
    public String getActionnCommand() {return command; }
    public int addItem() {return item; }
    public double totalAllInventory(CD[] cds) {
        double total = 0;
        for(int j = 0; j < cds.length; j++)
            total += cds[j].getSum();
        return total;
    }
}

public class InventoryI {
        
    String productnumber;
 
    String name;
 
    String Text;
        
        String fields;
        
        int numberofunits;
 
    double priceperunit;
        
        String itemcode; 
        
       
        

    // Create a new instance of Inventory
    // main constructor for the class
    public InventoryI(String Item_Number, String Item_Name, int Items_in_Stock,
            double Item_Price, String Item_Code) {
        productnumber = Item_Number;
        name = Item_Name;
        numberofunits = Items_in_Stock;
        priceperunit = Item_Price;
                itemcode = Item_Code;
                
                
       
    }        
 
    public void setItemName(String Item_Name) {
    // sets the items name

        name = Item_Name;
    }
 
    public void setItemCode(String Item_Code) {
    // sets the items name

        itemcode = Item_Code;
    }
        public void setItemNumber(String Item_Number) { // Sets the Product =Number
    // for the item
 
        productnumber = Item_Number;
    }
 
    public void setItemsInStock(int Items_in_Stock) { // sets the =number of
    // units in stock
 
        numberofunits = Items_in_Stock;
    }
 
    public void setItemPrice(double Item_Price) { // sets the price of =the
    // item
        priceperunit = Item_Price;
     
    }
       
        public String getItemName() { // returns the Product Name of this item
        return name;
    }
 
     public String getItemCode() { // returns the Product Name of this item
        return itemcode;
        }
         
        public String getItemNumber() { // returns the Product Number of the =item
 
        return productnumber;
    }
 
    public int getItemsInStock() { // returns how many units are in stock
        return numberofunits;
    }
 
    public double getItemPrice() { // returns the price of the item
        return priceperunit;
    }
 
    public double getInventoryIValue() { // returns the total value of =the stock
    // for this item
        return priceperunit * numberofunits;
    }
        
    public static double getTotalValueOfAllInventory(InventoryI [] inv) {
    
            double tot = 0.0;
        
        for(int i = 0; i < inv.length; i++)   
                
            tot += inv[i].getInventoryIValue();
        
        return tot;
        
    }
    
    public static InventoryI[] sort(InventoryI [] inventory)
    {
        InventoryI temp[] = new InventoryI[1];
         
        //sorting the array using Bubble Sort
        for(int j = 0; j < inventory.length - 1; j++)
        {
         
            for(int k = 0; k < inventory.length - 1; k++)
            {
         
                if(inventory[k].getItemName().compareToIgnoreCase(inventory[k+1].getItemName()) > 0)
                {
         
                    temp[0] = inventory[k];
                    inventory[k] = inventory[k+1];
                    inventory[k+1] = temp[0];
         
                }//end if
         
            }//end for loop
         
        }//end for loop

        
        return inventory;
                
    }
    
    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        
                
        sb.append("CD Title:      \t").append(name).append("\n");
                sb.append("Item Code:      \t").append(itemcode).append("\n");
        sb.append("Item #:           \t").append(productnumber).append("\n");
        sb.append("Number in stock:\t").append(numberofunits).append("\n");
        sb.append("Price:          \t").append(String.format("$%.2f%n", priceperunit));
        sb.append("Inventory Value:\t").append(String.format("$%.2f%n", this.getInventoryIValue()));
 
        return sb.toString();
                
                
    }
    
    
}

I feel like I'm overdosed on coffee, I have consumed so much coffee to stay up and finish this assignment. I cant fall asleep or i will miss my class and fail my assignment. but I guess thats no ones fault but my own.

0

Your event handlers produce outcome/action exactly what you tell them to do

jbtAdd.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                dispProd = 11;
                
                populateFields(dispProd);
                
            } // end addBtn actionEvent
            
        }); // end addBtn actionListener        
       
         jbtDelete.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            dispProd = 0;
            
            } // end deleteBtn actionEvent
         }); // end deleteBtn actionListener
         
         jbtModify.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                
            for(int j = 0; j < productCD.length; j++)
            populateFields(dispProd);
            
            } // end modifyBtn actionEvent
         }); // end modifyBtn actionListener
    }

Add will will move possition of pointer to 11 and display array data from this position which will be EMPTY as you did not read any of yours JTextFields and did not store this data in next empty array position
Delete will move pointer to first position in array and that's it! This will only affect functionality of button Next and Previous.
Modify will first go throught for loop and then re-populate JTextFields whit same data as there been previously

I recomend you create search method, which will be called once Modify or Delete button pressed. When you call this method as the argument pass content(string) of Item Name JTextField. Inside search method you can use for loop to go throught your productCD array with if statement to check productCD ItemName equals to PASSED_ARGUMENT. Once item found initialize local variable with current value of variable used in for loop and return this value to method which requested search method.
Modify method then should use set methods to update selected item productCD[RETURNED_INT] with new ItemPrice/units/code.
Delete will however assign empty string ("") to string variables and zero to integer/double variables

0

My brain is in shock or something because I have read so many tutorials and what-knot that all the information is in gridlock and scrambled. I am so lost. if you only knew how long that I have been sitting here on my computer reeading and trying so many different thing. I feel retarded because I know its somethinng that I am overlooking. I dont want to fail my class but I dont know what else to do and my head is about to explode. maybe I should have slept so I could started fresh
Thank you for your help peter, you have been a god sent and have been pacient with me. I really do appreciate it.

0

I would like to thank Ezzaral and peter_budo for helping me bettter understand java. I learned more from you guys in just a short time than I did from my class and instructor.
Thank you very much.

0

I tried to run this code as written

Correction... I tried to compile the code as written

I got a ".\ActionListener.java: class, interface, or enum expected" for every single line of code.

That makes no sense! I have tried to reveiw the tutorials on ActionListener and its implementation but I'm having trouble connecting the dots.

Is there a significant change from Java 1.4 to the 1.5 and beyond. I think I have JDK suite installed on my CPU.

or is there a gap in the program I just missed or is 'assumed' and just not written in.

0

Yes there lots of differences between this two versions. However you should speed up as there is Java 1.6 aviable over a year already

0

I am also doing inventoy program 5 but my issue is that i have an double array.
an honestly i can think of a way to get the info to diplay one at a time because of this. i dont know if i would be better of swiching to a singal array or if i can do a if loop some how.

this is what i have so far if someone could point me in the right way that would be great because im not get much help from my teach.

import java.awt.*;
import javax.swing.*;



public class iteminventory7

{

    /** Creates a new instance of StoreItemInventory */

    public static void main (String[] args)

    {

        double Game[][] = { { 1550, 100, 230.5, 0 },
                            { 1552, 110, 220.5, 0 },
                            { 1553, 10, 120.5, 0 },
                            { 1554, 200, 20.75, 0 },
                            { 1555, 130, 20.35, 0 },
                            { 1556, 120, 22.5, 0 },
                            { 1557, 100, 50.5, 0 },
                            { 1558, 111, 40.5, 0 },
                            { 1559, 220, 30.5, 0 },
                            { 1560, 133, 20.5, 0 },
                            { 1561, 1220, 10.5, 0 } };

        iteminventory myGame = new iteminventory( "Items","Out of this World !!!", Game );
        myGame.displaymessage();
        myGame.outputitems();
    }


    public static class iteminventory
    {
        /** Creates a new instance of iteminventory */
        private String storeName;
        private String itemName;
        private double Game[][];
        private double Itemvalue;
        private int UnitAmount;
        private double Restockfee;



        public iteminventory(String name, String Sname, double GameArray[][])
        {
            storeName = Sname;
            itemName = name;
            Game = GameArray;
        }


        public String getstoreName()
        {
            return storeName;
        }


        //displays main message
        public void displaymessage()
        {
            System.out.printf( "Welcome to our Store : %s!\n", getstoreName());
        }


        // method returning itemname
        public String getitemName()
        {
            return itemName;
        }


        // method setting itemname
        public void setitemName(String name, int index)
        {
            itemName = name;
        }


        //performs the various operations on the item inventory info
        public double gettotal(int atcount )
        {
            double total = 0.0; // initialize total
            // sum inventory average
            total = (Game[atcount][1]) * (Game[atcount][2]);
            return total;
        }

        //prints out a listing of the item information

        public double getRestockfee(int atcount )
        {
            double total2 = 0.0; // sum inventory average
            total2 = (Game[atcount][1]) * (Game[atcount][2] * 0.05);
            return total2;
        }



        //prints out a listing of the item information
        public void outputitems()
        {

            Labels mylabels = new Labels(); // create Labels
            mylabels.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            mylabels.setSize(535, 480); // set frame size
            mylabels.setVisible( true ); // display frame

        }




        public class Labels extends JFrame
        {

            private JLabel itemNameLabel;
            private JLabel itemNumberLabel;
            private JLabel UnitAmountLabel;
            private JLabel ItemvalueLabel;
            private JLabel InventoryvalueLabel;
            private JLabel RestockingfeeLabel;
            private JLabel totalInventoryValueLabel;
            private JFrame frame = new JFrame();
            private TextArea text = new TextArea();
            //frame.getContentPane();add(BorderLayout.WEST, JLabels);



            //  Labels constructor adds JLabels to JFrame
            public Labels()
            {
                super( "Inventory Program" );
                setLayout( new FlowLayout() ); // set frame layout

                // JLabel constructor
                text.setSize(50,485);
                itemNameLabel = new JLabel("Name:  ");
                itemNameLabel.setToolTipText("Name Label  ");
                add( itemNameLabel ); // add bookTitleLabel to JFrame
                itemNumberLabel = new JLabel("Item Number:  ");
                itemNumberLabel.setToolTipText("Item Number Label  ");
                add( itemNumberLabel ); // add itemNumberLabel to JFrame
                UnitAmountLabel = new JLabel("UnitAmount:  ");
                UnitAmountLabel.setToolTipText("UnitAmount Label");
                add( UnitAmountLabel ); // add bookUnitsLabel to JFrame
                ItemvalueLabel = new JLabel("Item Price:   ");
                ItemvalueLabel.setToolTipText("Item Price Label");
                add( ItemvalueLabel ); // add bookPriceLabel to JFrame
                InventoryvalueLabel = new JLabel("Inventory Value:   ");
                InventoryvalueLabel.setToolTipText("Inventory Value Label");
                add ( InventoryvalueLabel ); // add inventoryValueLabel to JFrame
                RestockingfeeLabel = new JLabel("Restocking Fee:    ");
                RestockingfeeLabel.setToolTipText("Restocking Fee Label");
                add( RestockingfeeLabel ); // add bookRestockingFeeLabel to JFrame
                add(text);
                text.setText(getstoreName());
            } // end Label constructor

        } // end class Labels
    }
}

I know how to do a button for a single array button I so lost Im on my 7th file trying to figure out how to do this with a double array. I know im making this a lot harder then it real is but i think my brain stop working somewhere along the 5 file. well tell me what you guys think if its a lose or if i can use so type of loop. i think an if and a else loop would work or if i would just be better off going with a single array

thanks for the help and if it seems like im asking for code im sorry im not the best at wording this type of stuff.

Edited by mike_2000_17: Fixed formatting

0

I am also doing inventoy program 5 but my issue is that i have an double array.
an honestly i can think of a way to get the info to diplay one at a time because of this. i dont know if i would be better of swiching to a singal array or if i can do a if loop some how.
...<snipped>

Please post questions as a new thread and be sure to place code tags around all code that is posted. See the announcement at the top of the forum if you do not know how to use the code tags. Also, the coding conventions published by Sun are worth a read http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.