Hi Everyone I am new and just found this site yesturday I am looking forward to visiting here often.

I have been working on this project (yes for school the awful Inventory Program.)

I had it working and did a couple of quick changes walked away for a nap and now it won't launch the GUI and I didn't take notes on what I did.
Everything looks like it is there so now I am going through my code and checking to see if something is causing it not to launch or if I accidently deleted something when I was cleaning it up to turn in.

I was just wondering if I could invite you to look with me :$
I feel so stupid about this but I am so tired and my brain is mush :zzz:

I thank those who are up to the challenge in advance.

Here is my code

package inventoryfinal;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;

public class Inventory {

   private String inventoryName; // name of inventory

   public String restockRate; // restock rate percentage

   public double totalRestock;

   public static int index;

   public ArrayList < ProductModified > products = new ArrayList < ProductModified > ();

   public Inventory()
   {
      products.add( new ProductModified( "Wanted", 0, 1, 0.00 ) );
      products.add( new ProductModified( "Death Race", 7, 52, 160.00 ) );
      products.add( new ProductModified( "Harry Potter", 16, 61, 97.00 ) );
      products.add( new ProductModified( "Repo", 25, 106, 88.00 ) );
      products.add( new ProductModified( "Matrix", 34, 125, 79.00 ) );
      products.add( new ProductModified( "Mamma Mia", 0, 124, 70.00 ) );

      index = 0;
   }

   public void sort()
   {
      Locale loc = Locale.ENGLISH;

      ProductModified Temp;

      Collator col = Collator.getInstance( loc );

      for ( int i = 0; i < products.size(); i++ )
      {
         for ( int j = i + 1; j < products.size(); j++ )
         {
            if( col.compare( products.get( i ).getDVDName(), products.get( j ).getDVDName() ) > 0 )
            {
               Temp = products.get( i );

               products.set( i, products.get( j ) );
               products.set( j, Temp );
            }
         }
      }
   }

   public String getInventoryName()
   {
      return inventoryName;
   }

    public void setInventoryName( String inventoryName )
    {
       this.inventoryName = inventoryName;
    }

    public String getRestockRate()
    {
       return restockRate;
    }

    public void setRestockRate( String restockRate )
    {
       this.restockRate = restockRate;
    }

    public double getTotalRestock()
    {
       return totalRestock;
    }

    public void setTotalRestock( double totalRestock )
    {
       this.totalRestock = totalRestock;
    }

    public ArrayList < ProductModified > getproducts()
    {
       return products;
    }

    public void seproducts( ArrayList < ProductModified > products)
    {
       this.products = products;
    }

    @Override
    public String toString()
    {
       String DVDSub = new String(" ");

       DVDSub = "Welcome to the\n" + getInventoryName() + "!\n\n";

       DVDSub = DVDSub + "Below is the available inventory:\n\n";

       DVDSub = DVDSub + "The restock interest rate is at " + getRestockRate() + ".\n\n";

       DVDSub = DVDSub + "Index\tProductModified #\t\t\tName\t\tUnits\t\tPrice\t\t";

       DVDSub = DVDSub + "Unit Restock Value\t";

       DVDSub = DVDSub + "Stock Value\t\t";

       DVDSub = DVDSub + "Total ProductModified Restock\n";

       Iterator < ProductModified > i = this.getproducts().iterator();

       while(i.hasNext())
       {
          DVDSub = DVDSub + i.next();
       }

      return DVDSub;
   }

   public Double getTotal()
   {
      Double Total = 0.0;

      ProductModified p;

      Iterator < ProductModified > i = products.iterator();

      while( i.hasNext() )
      {
            p = i.next();

            Total = Total + p.getPrice() * p.getUnit();
      }

      return Total;
   }

   public String processOutPut( ProductModified p )
   {
      String out = "Welcome Mari's Inventory\n\nTotal Inventory = "
      + this.getTotal() + "\nRestocking Fee = 5%"
      + "\n\nItem #\tName\tUnit\tPrice\tUnit Restock Value"
      + p;

      return out;
   }

   public String getFirst()
   {
      index = 0;

      return processOutPut( products.get(0) );

   }

   public String getLast()
   {
      index = products.size() - 1;

      return processOutPut( products.get( products.size() - 1 ) );
   }

   public String getNext()
   {
      if( index == products.size() - 1 )
      {
         getFirst();

         return getFirst();
      }

      else
      {
         index++;

         return processOutPut( products.get( index ) );
      }
   }

   public String getPrevious()
   {
      if( index == 0 )
      {
         return getLast();
      }

      else {
            return processOutPut(products.get(--index));
        }
   }

   public String Search( String Search )
   {
      Iterator < ProductModified > i = products.iterator();

      String te = null;

      ProductModified p;

      while( i.hasNext() )
      {
         p = i.next();

         if( p.getDVDName().equals( Search ) )
         {
            te = processOutPut( p );
         }
      }

      return te;
   }


}
package inventoryfinal;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class InventoryDialogue extends JFrame implements ActionListener{

 private boolean status = false; //false is for modify

   JTextField nameTextField,
              unitTextField,
              priceTextField;

   JLabel nameLabel,
          unitLabel,
          priceLabel;

   JPanel TextFields,
          buttons;

   JButton modify,
           add;

   public InventoryDialogue( Boolean stat, String title )
   {
      super( title );
      status = stat;
      JPanel but = new JPanel();
      modify = new JButton( "Modify" );
      modify.addActionListener( this );
      add = new JButton( "Add" );
      add.addActionListener( this );
      but.add( add );
      but.add( modify );

      if( status == false )
      {
         add.setVisible( false );
      }

      else
      {
         modify.setVisible( false );
      }

      nameTextField = new JTextField( "", 20 );
      unitTextField = new JTextField( "", 5 );
      priceTextField = new JTextField( "" , 5 );
      nameLabel = new JLabel( "Name" );
      unitLabel = new JLabel( "Units" );
      priceLabel = new JLabel( "Price per Unit" );
      JPanel p = new JPanel();

      p.setLayout( new FlowLayout() );
      p.add( nameLabel );
      p.add( nameTextField );
      p.add( unitLabel );
      p.add( unitTextField );
      p.add( priceLabel );
      p.add( priceTextField );
      JPanel cp = new JPanel();

      cp.setLayout( new BorderLayout() );
      cp.add( p, BorderLayout.CENTER );
      cp.add( but, BorderLayout.EAST );
      this.setContentPane( cp );
      this.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
      this.pack();
      this.setVisible( true );
   }

   @Override
   public void actionPerformed( ActionEvent arg0 )
   {
      if( arg0.getActionCommand().equals( "Add" ) )
      {
         String name;
         int units;
         Double price;
         name = nameTextField.getText();

         try
         {
            units = Integer.parseInt( unitTextField.getText() );
         }

         catch ( NumberFormatException e )
         {
            JOptionPane.showMessageDialog( null, e.getMessage() );

            e.printStackTrace();

            return;
         }

         try
         {
            price = Double.parseDouble( priceTextField.getText() );
         }

         catch ( NumberFormatException e )
         {
            // TODO Auto-generated catch block
            JOptionPane.showMessageDialog( null, e.getMessage() );

            e.printStackTrace();

            return;
         }

         InventoryGUI.getInv().getproducts().add( new ProductModified( name, InventoryGUI.getInv().products.size(),
                                                                       units,price ) );

         this.dispose();
      }

      if( arg0.getActionCommand().equals( "Modify" ) )
      {
         String name;
         int units;
         Double price;
         name = nameTextField.getText();

         try
         {
            units = Integer.parseInt( unitTextField.getText() );
         }

         catch ( NumberFormatException e )
         {
            JOptionPane.showMessageDialog( null,"Please Enter Valid Integers" );

            e.printStackTrace();

            return;
         }

         try
         {
            price = Double.parseDouble( priceTextField.getText() );
         }

         catch ( NumberFormatException e )
         {
            // TODO Auto-generated catch block
            JOptionPane.showMessageDialog( null,"Please Enter Valid Price" );

            //e.printStackTrace();
            return;
         }

         InventoryGUI.getInv().getproducts().set( Inventory.index,
            new ProductModified( name, Inventory.index, units, price ) );

         this.dispose();
      }

   }

   public static void main( String args[] )
   {
      InventoryDialogue idf = new InventoryDialogue( true,"cc" );
   }


}
package inventoryfinal;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.Image;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;

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

public class InventoryGUI extends JFrame implements ActionListener{

private JTextArea textArea;

   private JButton first,
                   next,
                   previous,
                   last,
                   add,
                   modify,
                   delete,
                   save,
                   search,
                   exit;
   JLabel imageLabel;

   private static Inventory inv = new Inventory();

 
   public InventoryGUI( String arg0 ) throws HeadlessException
   {
      super( "Inventory GUI" );

      textArea = new JTextArea( 250,30 );

      JScrollPane scrollPane = new JScrollPane( textArea );

      textArea.setEditable( false );

      scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );

      scrollPane.setPreferredSize( new Dimension( 250, 250 ) );

      JPanel cp = new JPanel();

      cp.setSize( 250, 40 );

      cp.setLayout( new BorderLayout() );

      cp.add( scrollPane,BorderLayout.CENTER );

      JPanel buttonPaenl = new JPanel();

      JPanel buttonPaenl1 = new JPanel();

      first = new JButton( "First" );
      first.addActionListener( this );

      search = new JButton( "Search" );
      search.addActionListener( this );

      next = new JButton( "Next" );
      next.addActionListener( this );

      previous = new JButton( "Previous" );
      previous.addActionListener( this );

      last = new JButton( "Last" );
      last.addActionListener( this );

      add = new JButton( "Add" );
      add.addActionListener( this );

      modify = new JButton( "Modify" );
      modify.addActionListener( this );

      delete = new JButton( "Delete" );
      delete.addActionListener( this );

      save = new JButton( "Save" );
      save.addActionListener( this );

      exit = new JButton( "Exit" );
      exit.addActionListener( this );

      buttonPaenl.setLayout( new FlowLayout() );
      buttonPaenl1.setLayout( new FlowLayout() );
      buttonPaenl.add( first );
      buttonPaenl.add( previous );
      buttonPaenl.add( next );
      buttonPaenl.add( last );
      buttonPaenl1.add( add );
      buttonPaenl1.add( modify );
      buttonPaenl1.add( delete );
      buttonPaenl1.add( save );
      buttonPaenl1.add( search );
      buttonPaenl1.add( exit );

      cp.add( buttonPaenl,BorderLayout.SOUTH );
      cp.add( buttonPaenl1,BorderLayout.NORTH );
      cp.add( imageLabel,BorderLayout.EAST );
      this.setContentPane( cp );

      this.setTitle( " Week Nine Final Project: Inventory Program Part Six - Mari's Movies " );

      this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      this.textArea.setText(inv.getFirst());
      this.setSize(400, 400);
      this.pack();
      this.setVisible( true );

      Container pane = getContentPane();
      pane.setLayout(new GridLayout (4, 2));
   }

   @Override
   public void actionPerformed( ActionEvent e )
   {
 
      if( e.getActionCommand().equals( "First" ) )
      {
         textArea.setText( inv.getFirst() );
      }

      if( e.getActionCommand().equals( "Next" ) )
      {
         textArea.setText(inv.getNext());
      }

      if( e.getActionCommand().equals( "Previous" ) )
      {
         textArea.setText( inv.getPrevious() );
      }

      if( e.getActionCommand().equals( "Last" ) )
      {
         textArea.setText(inv.getLast());
      }

      if( e.getActionCommand().equals( "Save" ) )
      {
         save();
      }

      if( e.getActionCommand().equals( "Exit" ) )
      {
         System.exit(0);
      }

      if( e.getActionCommand().equals( "Add" ) )
      {
         InventoryDialogue id = new InventoryDialogue( true," Add a new Inventory " );
      }

      if( e.getActionCommand().equals( "Modify" ) )
      {
         InventoryDialogue id = new InventoryDialogue( false," Modify Inventory " );
      }

      if( e.getActionCommand().equals( "Search" ) )
      {
         String s = JOptionPane.showInputDialog( null, " Enter Product Name ",null, 1 );

         s = inv.Search(s);

         if( s == null )
         {
            JOptionPane.showMessageDialog( this, " No Results Found " );
         }

         else {
                textArea.setText(s);
            }
      }

      if( e.getActionCommand().equals( "Delete" ) )
      {
         inv.getproducts().remove( Inventory.index );
      }
      }
   

   public void save()
   {
      File f = new File( "C:\\data\\inventory.dat" );

      try
      {
         FileOutputStream out = new FileOutputStream( f );

         try
         {
            ObjectOutputStream objectOut = new ObjectOutputStream( out );
               objectOut.writeObject( inv );
         }

         catch (IOException e)
         {
            // TODO Auto-generated catch block
            JOptionPane.showMessageDialog( null, e.getMessage() );
               e.printStackTrace();
         }
      }

      catch ( FileNotFoundException e )
      {
         // TODO Auto-generated catch block
         JOptionPane.showMessageDialog( null, e.getMessage() );
            e.printStackTrace();
      }

   }

   public static Inventory getInv()
   {
      return inv;
   }

   public static void setInv( Inventory inv )
   {
      InventoryGUI.inv = inv;
   }

   public static void main( String[] args )
   {
      InventoryGUI inventory = new InventoryGUI( "Inventory" );
   }
}
package inventoryfinal;

public class Product {

 
    public static void main(String[] args) {
       
    }
 
   public int productNumber; // product # array ID for product
   public int unit; // array of autobot toy units
   public double price; // array of autobot prices
   public double inventoryValue;
    private String DVDName;



   public Product( String DVDName, int productNumber, int unit,
                   double price )
   {
      super();
      this.DVDName = DVDName;
      this.productNumber = productNumber;
      this.unit = unit;
      this.price = price;
   }

   public String getDVDName()
   {
      return DVDName;
   }

   public void setDVDName( String autobotName )
   {
      this.DVDName = autobotName;
   }

   public int getProductNumber()
   {
      return productNumber;
   }

   public void setProductNumber( int productNumber )
   {
      this.productNumber = productNumber;
   }

   public int getUnit()
   {
      return unit;
   }

   public void setUnit( int unit )
   {
      this.unit = unit;
   }

   public double getPrice()
   {
      return price;
   }

   public void setPrice( double price )
   {
      this.price = price;
   }

   public double getInventoryValue()
   {
      return inventoryValue;
   }

   public Double inventoryValue()
   {
      return this.getPrice() * this.getUnit();
   }

    @Override
   public String toString()
   {
      return "\n"+this.productNumber+"\t"+this.DVDName+"\t"+this.unit +"\t"+this.price+ "\t";
   }
 
}
package inventoryfinal;

public class ProductModified extends Product{
    private String MovieName;


   public ProductModified( String DVDName, int productNumber, int unit,
                           double price )
   {
      super( DVDName, productNumber, unit, price );
      this.inventoryValue = this.inventoryValue();
      
   }

 
   public Double inventoryValue()
   {
      return this.getUnit() * this.getPrice() + this.getUnit() * this.getPrice() * 0.05;
   }


   public String toString()

   {
      return "\n" + this.productNumber + "\t" + this.MovieName
                  + "\t" + this.unit + "\t" + this.price + "\t"
                  + this.getInventoryValue();
   
}

}

:*

Hello bunifrog.
Initialize imageLabel.
Temporaily delete ProductModified. You can use function with a coefficient value 1.0 or 1.05 to calculate inventoryValue().

quuba thanks so much for answering I really am gratefull.

I did as you said and it messed up all of the classes.
Not sure how you ment for me to do it but again thanks for answering I am just so new at this and after 4 days it is all blurring together.

You posted much too much code. If your GUI isn't launching it is probably because you didn't call setVisible(true) on the JFrame, but who knows since I didn't manage to find your main method after scrolling through.

After doing ctrl+f to find your code, then doing it again to find your constructor for InventoryDialog, it seems like your GUI isn't launching because you never added the panel to the frame. Your "main" panel is called cp. You should have called this.add(cp) somewhere, since your class extends JFrame, but it doesn't look like you did. So unless I missed where you did that, when you run your code, you would see nothing but an empty JFrame. Also, make sure you called setVisible(true) somewhere after everything is added to the JFrame also.

Second view to inventoryfinal:
Inside InventoryGUI constructor
//1. scrollPane.setPreferredSize(new Dimension(250, 250)); not needed
//2.

JPanel cp = new JPanel(){
            public Dimension getPreferredSize(){
                return new  Dimension(500, 200);
            }
        };

//3. cp.setSize(350, 40); pack() change this
//4. cp.add(imageLabel, BorderLayout.EAST); imageLabel not initialized
//5. this.setSize(400, 400); if pack() - no needed
//6. Container pane = getContentPane();
//7. pane.setLayout(new GridLayout(4, 2)); another one layout?

Inside ProductModified class
//8.private String MovieName; - not used, always null
//9.

public String toString() {
        return "\n" + this.productNumber + "\t" + this.getDVDName() + "\t" + this.unit + "\t" + this.price + "\t" + this.getInventoryValue();
    }

Comment some lines, change 2., 9.
Previously I wrote delete. Don't do it.

Thanks everyone you know you get to a point when it all just goes blurry and I had redone the code so many times by this point I lost the flow of it all. I managed to get it all rewrote and turned in on time but it is going to take me a week to recover from this week.

Again thanks everyone for posting It at least gives me something to play with later as I am going to practice until my next class starts lol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.