GUI Delete Button Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ITAutobot25
    New Member
    • Nov 2007
    • 7

    GUI Delete Button Problem

    My delete button is not working in my GUI and my due date is today before midnight. Can anyone show me how to correct this error? My assignment statement is below as well as 5 classes. InventoryGUI is the main class to begin execution.
    Thanks!

    • 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\invento ry.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.

    Code:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    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,Serializable 
    {
       private JTextArea textArea;
       
       private JButton first,
                       next,
                       previous,
                       last,
                       add,
                       modify,
                       delete,
                       save,
                       search,
                       exit;
       JLabel imageLabel;
       
       private static Inventory inv = new Inventory();
    
       /**
    	 * @param arg0
    	 * @throws HeadlessException
    	 */
       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 );
    
    	  ImageIcon icon = new ImageIcon( "C:\\data\\logo.gif","a pretty but meaningless splat" );
    	  imageLabel = new JLabel( "Xavier", icon, JLabel.CENTER );
    	  cp.add( imageLabel,BorderLayout.EAST );
    	  this.setContentPane( cp );
    
    	  this.setTitle( " Week Nine Final Project: Inventory Program Part Six - Transformers Autobot Inventory ( More Than Meets the Eye o_0?! ) " );
    
    	  this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          this.textArea.setText(inv.getFirst());
          this.setSize(400, 400);
    	  this.pack();
    	  this.setVisible( true );
       }
    
       @Override
       public void actionPerformed( ActionEvent e ) 
       {
          // TODO Auto-generated method stub
          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( inv.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;
       }
    
       /**
    	* @param args
    	*/
       public static void main( String[] args ) 
       {
          InventoryGUI inventory = new InventoryGUI( "Inventory" );
       }
    }
    Code:
    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( InventoryGUI.getInv().index, 
                new ProductModified( name, InventoryGUI.getInv().index, units, price ) );
    			
    	     this.dispose();
          }
    
       }
       
       public static void main( String args[] )
       {
          InventoryDialogue idf = new InventoryDialogue( true,"cc" );
       }
    }
    Code:
    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( "No Sale Bot", 0, 1, 0.00 ) );
          products.add( new ProductModified( "Optimus Prime", 7, 52, 160.00 ) );
          products.add( new ProductModified( "BumbleeBee", 16, 61, 97.00 ) );
          products.add( new ProductModified( "Ironhide", 25, 106, 88.00 ) );
          products.add( new ProductModified( "Ratchet", 34, 125, 79.00 ) );
    	  products.add( new ProductModified( "Jazz", 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 ).getAutobotName(), products.get( j ).getAutobotName() ) > 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;
    	}
    	
    	public String toString()
        {
    	   String transformersSub = new String(" ");
    
    	   transformersSub = "Welcome to the\n" + getInventoryName() + "!\n\n";
    
    	   transformersSub = transformersSub + "Below is the available inventory:\n\n";
    
    	   transformersSub = transformersSub + "The restock interest rate is at " + getRestockRate() + ".\n\n";
    
    	   transformersSub = transformersSub + "Index\tProductModified #\t\t\tName\t\tUnits\t\tPrice\t\t";
    
    	   transformersSub = transformersSub + "Unit Restock Value\t";	
    
    	   transformersSub = transformersSub + "Stock Value\t\t";
    
    	   transformersSub = transformersSub + "Total ProductModified Restock\n";
    	   
    	   Iterator < ProductModified > i = this.getproducts().iterator();
    	   
    	   while(i.hasNext())
    	   {
    	      transformersSub = transformersSub + i.next();
    	   }
    	   
          return transformersSub;
       }
       
       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 to the Transformers Autobot Toy 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.getAutobotName().equals( Search ) )
             {
    	        te = processOutPut( p );
             }
          }
          
          return te;
       }
    }
    Code:
    import static java.lang.System.out;
    
    
    //class declaration for TransformersProduct
    public class Product
    {
       public String autobotName; // array of autobot toy names
       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;
    	
       /**
    	* @param autobotName
    	* @param productNumber
    	* @param unit           
    	* @param price
    	*/
       
       public Product( String autobotName, int productNumber, int unit,
    			       double price ) 
       {
          super();
    	  this.autobotName = autobotName;
    	  this.productNumber = productNumber;
    	  this.unit = unit;
    	  this.price = price;
       }
    
       public String getAutobotName() 
       {
          return autobotName;
       }
       
       public void setAutobotName( String autobotName ) 
       {
          this.autobotName = 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();
       }
       
       public String toString()
       {
          return "\n"+this.productNumber+"\t"+this.autobotName+"\t"+this.unit +"\t"+this.price+ "\t"; 
       }
    }
    Code:
    public class ProductModified extends Product 
    {
       public ProductModified( String autobotName, int productNumber, int unit,
    			               double price ) 
       {
          super( autobotName, productNumber, unit, price );
    	  this.inventoryValue = this.inventoryValue();
    	  // TODO Auto-generated constructor stub
       }
    	
       public Double inventoryValue()
       {
          return this.getUnit() * this.getPrice() + this.getUnit() * this.getPrice() * 0.05;
       }
       
       public String toString()
       {
          return "\n" + this.productNumber + "\t" + this.autobotName 
                      + "\t" + this.unit + "\t" + this.price + "\t" 
                      + this.getInventoryValue(); 
       }
    }
  • ITAutobot25
    New Member
    • Nov 2007
    • 7

    #2
    I managed to get the "Delete" button to work. I just have one last problem dealing with the "Save" button execution.

    When I click on save, it does create a inventory.dat file in my Data folder located my C: drive. However, when I review my General Output screen, I can this message:

    "--------------------Configuration: <Default>--------------------
    java.io.NotSeri alizableExcepti on: Inventory
    at java.io.ObjectO utputStream.wri teObject0(Objec tOutputStream.j ava:1156)
    at java.io.ObjectO utputStream.wri teObject(Object OutputStream.ja va:326)
    at InventoryGUI.sa ve(InventoryGUI .java:211)
    at InventoryGUI.ac tionPerformed(I nventoryGUI.jav a:161)
    at javax.swing.Abs tractButton.fir eActionPerforme d(AbstractButto n.java:1995)
    at javax.swing.Abs tractButton$Han dler.actionPerf ormed(AbstractB utton.java:2318 )
    at javax.swing.Def aultButtonModel .fireActionPerf ormed(DefaultBu ttonModel.java: 387)
    at javax.swing.Def aultButtonModel .setPressed(Def aultButtonModel .java:242)
    at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Bas icButtonListene r.java:236)
    at java.awt.Compon ent.processMous eEvent(Componen t.java:6038)
    at javax.swing.JCo mponent.process MouseEvent(JCom ponent.java:326 0)
    at java.awt.Compon ent.processEven t(Component.jav a:5803)
    at java.awt.Contai ner.processEven t(Container.jav a:2058)
    at java.awt.Compon ent.dispatchEve ntImpl(Componen t.java:4410)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2116)
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:4240)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent(Container. java:4322)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(Container.j ava:3986)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Container.java: 3916)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2102)
    at java.awt.Window .dispatchEventI mpl(Window.java :2429)
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:4240)
    at java.awt.EventQ ueue.dispatchEv ent(EventQueue. java:599)
    at java.awt.EventD ispatchThread.p umpOneEventForF ilters(EventDis patchThread.jav a:273)
    at java.awt.EventD ispatchThread.p umpEventsForFil ter(EventDispat chThread.java:1 83)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(EventDis patchThread.jav a:173)
    at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:168)
    at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:160)
    at java.awt.EventD ispatchThread.r un(EventDispatc hThread.java:12 1)"

    Is this normal? Is the program saving correctly? I have no idea if it is because I don't know what program to use to open the inventory.dat file to check. When I click on it, the file opens in notepad and I get...

    "¬í {sr java.io.NotSeri alizableExcepti on(Vx ç†5 xr java.io.Object StreamException dÃäk9ûß xr java.io.IOExce ptionl€sde%ð« xr java.lang.Exce ptionÐý>;Ä xr java.lang.Thro wableÕÆ5'9w¸Ë L causet Ljava/lang/Throwable;L
    detailMessaget Ljava/lang/String;[
    stackTracet [Ljava/lang/StackTraceEleme nt;xpq ~ t Inventoryur [Ljava.lang.Stac kTraceElement; F*<<ý"9 xp sr java.lang.Stac kTraceElementa Åš&6Ý… I
    lineNumberL declaringClass q ~ L fileNameq ~ L
    methodNameq ~ xp „t java.io.Object OutputStreamt ObjectOutputSt ream.javat writeObject0sq ~ Fq ~ q ~ t writeObjectsq ~ Ót InventoryGUIt InventoryGUI.j avat savesq ~ ¡q ~ q ~ t actionPerforme dsq ~ Ët javax.swing.Ab stractButtont AbstractButton .javat fireActionPerf ormedsq ~ t "javax.swing.Ab stractButton$Ha ndlerq ~ q ~ sq ~ ƒt javax.swing.De faultButtonMode lt DefaultButtonM odel.javaq ~ sq ~ òq ~ q ~ !t
    setPressedsq ~ ìt *javax.swing.pl af.basic.BasicB uttonListenert BasicButtonLis tener.javat
    mouseReleasedsq ~ –t java.awt.Compo nentt Component.java t processMouseEv entsq ~ ¼t javax.swing.JC omponentt JComponent.jav aq ~ +sq ~ «q ~ )q ~ *t processEventsq ~ 
    t java.awt.Conta inert Container.java q ~ 0sq ~ :q ~ )q ~ *t dispatchEventI mplsq ~ Dq ~ 2q ~ 3q ~ 5sq ~ q ~ )q ~ *t
    dispatchEventsq ~ ât java.awt.Light weightDispatche rq ~ 3t retargetMouseE ventsq ~ ’q ~ :q ~ 3q ~ +sq ~ Lq ~ :q ~ 3q ~ 8sq ~ 6q ~ 2q ~ 3q ~ 5sq ~ }t java.awt.Windo wt Window.javaq ~ 5sq ~ q ~ )q ~ *q ~ 8sq ~ Wt java.awt.Event Queuet EventQueue.jav aq ~ 8sq ~ t java.awt.Event DispatchThreadt EventDispatchT hread.javat pumpOneEventFo rFilterssq ~ ·q ~ Gq ~ Ht pumpEventsForF iltersq ~ *q ~ Gq ~ Ht pumpEventsForH ierarchysq ~ ¨q ~ Gq ~ Ht
    pumpEventssq ~ q ~ Gq ~ Hq ~ Osq ~ yq ~ Gq ~ Ht runx"

    This does not look right; it looks very similar to what I get in the General Output screen. I was expecting to see a saved inventory list. Other than that, I believe I met the requirements of this assignment. If something is not working with the save feature, what is needed to correct the problem? Thanks.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      You are trying to (de)serialize your Inventory class. By convention Java can only
      (de)serialize objects if they implement the (empty) Serializable interface; as in:

      [code=java]
      public class Inventory implements Serializable { ... }
      [/code]

      This is basically all you have to do for a class if you want to make it serializable.
      Note that if your class contains other class objects, they have to be serializable
      as well.

      kind regards,

      Jos

      Comment

      • ITAutobot25
        New Member
        • Nov 2007
        • 7

        #4
        Thanks a bunch! I've implemented the serialization to the Inventory and ProductModified class (I also implemented it in the Product class; however, I received the same output whether I implemented it or not. Therefore, took it out of the Product class).

        Now, the inventory.dat file produced something different, which is:

        "¬í sr InventoryQ‰%wñ Ít D totalRestockL
        inventoryNamet Ljava/lang/String;L productst Ljava/util/ArrayList;L restockRateq ~ xp psr java.util.Arra yListxÒ™Ça I sizexp w
        sr ProductModifie dà_û©· xr ProductŸX>i¿  D inventoryValue D priceI
        productNumberI unitL autobotNameq ~ xp t No Sale Botsq ~ @Á @d  4t
        Optimus Primesq ~ @¸DÙ™™™š@X@  =t
        BumbleeBeesq ~ @Ã!33333@V  jt Ironhidesq ~ @Ä@` @SÀ " }t Ratchetsq ~ @ÁÍ @Q€ |t Jazzxp"

        It still looks kind of funny...is it suppose to look that way? I think it is suppose to look that way because in the past, I experimented on opening files with the wrong programs and I get something to that effect. Maybe I need to open it with another program other than notepad so it can be viewed better (I don't know of a program to open .dat files), or maybe the only way to view it correctly is if I had a Load feature in my Inventory Program; however, that's not required for this assignment (I might implement that feature later on after I submit this just because....).

        Please let me know (or anyone else) if everything is ok (and what program to use to view the .dat file correctly....if available). I thank you a bunch again!

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by ITAutobot25
          Thanks a bunch! I've implemented the serialization to the Inventory and ProductModified class (I also implemented it in the Product class; however, I received the same output whether I implemented it or not. Therefore, took it out of the Product class).
          For an Inventory object to be serializable all of its members need to be serializable.
          An Inventory object contains other object types so they too need to implement
          the Serializable interface. Also re-read what I wrote in my previous reply.

          Originally posted by ITAutobot25
          Now, the inventory.dat file produced something different, which is:

          [ snip ]

          It still looks kind of funny...is it suppose to look that way? I think it is suppose to look that way because in the past, I experimented on opening files with the wrong programs and I get something to that effect. Maybe I need to open it with another program other than notepad so it can be viewed better (I don't know of a program to open .dat files), or maybe the only way to view it correctly is if I had a Load feature in my Inventory Program; however, that's not required for this assignment (I might implement that feature later on after I submit this just because....).

          Please let me know (or anyone else) if everything is ok (and what program to use to view the .dat file correctly....if available). I thank you a bunch again!
          A serialized object isn't just text, i.e. it is a binary representation of the object.
          I've seen that gibberish before and it looks fine, it just isn't plain text. You can
          open that file for reading again, wrap an ObjectInputStre am around it and read
          the entire Inventory object back in in one read call. It is sort of symmetrical to
          how you wrote the object.

          kind regards,

          Jos

          Comment

          • ITAutobot25
            New Member
            • Nov 2007
            • 7

            #6
            How to create an empty folder in C: drive

            Thank you again for your input. One last thing, if you could point me in the right direction with a nice trail :). My assignment requires that I use exception handling to create a directory and file if necessary.

            I was able to create a C:data\inventor y.dat file, provided that there's an existing Data folder (directory) in my C: drive; however, I have a feeling that the assignment wants me to create an actual Data folder if one is not available. When I remove the Data folder from my C: drive, I get "C:\data\invent ory.dat (The system cannot find the path specified)".

            How am I to create able a folder that currently does not exist? Thank you again.
            Last edited by ITAutobot25; Nov 18 '07, 10:21 AM. Reason: Correcting a typo

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by ITAutobot25
              Thank you again for your input. One last thing, if you could point me in the right direction with a nice trail :). My assignment requires that I use exception handling to create a directory and file if necessary.

              I was able to create a C:data\inventor y.dat file, provided that there's an existing Data folder (directory) in my C: drive; however, I have a feeling that the assignment wants me to create an actual Data folder if one is not available. When I remove the Data folder from my C: drive, I get "C:\data\invent ory.dat (The system cannot find the path specified)".

              How am I able a folder that currently does not exist? Thank you again.
              Have a look at the File class and pay close attention to the mkdirs
              method. Alternatively you can use the FileSystemView class.

              kind regards,

              Jos

              Comment

              • ITAutobot25
                New Member
                • Nov 2007
                • 7

                #8
                Thanks a bunch! I got it to work. I do have one last problem that I will post in new topic.

                Comment

                Working...