Integer Field in JList ... renumbering

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • no1zson
    New Member
    • Jul 2007
    • 38

    #1

    Integer Field in JList ... renumbering

    I do not even know how to correctly ask this question.
    I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number.
    Over the last week I have played with Add buttons, Del buttons, Modify and everything else and it brought to light a problem I want to address today.
    I have always just used 1 for the first item, 2 for the second and so on ...
    well after I am done will all the button nonsence the item numbers are all over the place.
    How could I make it so that the item number field would be restructured and stay in ascending order no matter what was added or deleted?
    If I delete cd number 4, then make 5 number 4, 6 number 5 and so on ... the next cd added should just take the next highest number ...
    Does that make sense?
    Here is my primary class. I can post the others if needed.

    Code:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.text.*;
    import java.lang.*;
    import javax.swing.JFrame;
    
    public class Inventory2 extends JFrame
    {
    	private JLabel cdNameLabel; // name label 
    	private JLabel artistLabel; // item number label 
    	private JLabel nstockLabel; // units in stock label 
    	private JLabel priceLabel; // price each label 
    	private JLabel itemLabel; // item number label 
    	private JTextField cdNameField; // name display 
    	private JTextField artistField; // artist display 
    	private JFormattedTextField nstockField; // units in stock display 
    	private JFormattedTextField priceField; // price each display 
    	private JTextField itemField; // item number display 
    	private NumberFormat nstockFormat; // format field and parse numbers 
    	private NumberFormat priceFormat; // format field and parse numbers 
    	private JButton btnAdd; // first button 
    	private JButton btnPrev; // previous button 
    	private JButton btnNext; // next button 
    	private JButton btnDel; // last button 
    	private JButton btnFirst; // first button
    	private JButton btnLast; // last button
    	private JButton btnModify; // modify button
    	private JButton btnSave; // save button
    	private JButton btnSearch; // search button
    	private JPanel buttonJPanel; // JPanle to hold buttons 
    	private JPanel fieldJPanel; // JPanel to hold labels and displays 
    	private JPanel fontJPanel; // JPanel to display logo 
    	private int currCD; 
    	private double total = 0; // variable for total inventory 
    	private JList Inventorylist; // JList to take place of old array
    	private DefaultListModel listModel;
    	private JScrollPane jScrollPanel;  
    	private float Invtotal = .00f;
    	
    	 DecimalFormat formatter = new DecimalFormat("0.00");
    	
    	public Inventory2() // create class and method to perform GUI build 
    	{ 
    		initComponents(); 
    	} 
    
    	private void initComponents() 
    	{ 
    			
    		// create label names 
    		cdNameLabel = new JLabel("CD Name:"); 
    		artistLabel = new JLabel("Artist:");
    		nstockLabel = new JLabel("In Stock:"); 
    		priceLabel = new JLabel("Each Item Cost:$"); 
    		itemLabel = new JLabel("Item Number:"); 
     
    		
    		// initial fields
    		cdNameField = new JTextField(25);
    		cdNameField.setEditable(true);
    		artistField = new JTextField(15);
    		artistField.setEditable(true);
    		nstockField = new JFormattedTextField(nstockFormat);
    		nstockField.setEditable(true);
    		nstockField.setColumns(5);
    		priceField = new JFormattedTextField(priceFormat);
    		priceField.setEditable(true);
    		priceField.setColumns(5);
    		itemField = new JTextField(4);
    		itemField.setEditable(true);
    				
    		// JList
    		jScrollPanel = new JScrollPane();
    		Inventorylist = new JList(); 
    		currCD = 0;
    	
    				
    		// buttons 
    		btnAdd = new JButton(); 
    		btnNext = new JButton(); 
    		btnPrev = new JButton(); 
    		btnDel = new JButton();
    		btnLast = new JButton();
    		btnFirst = new JButton();
    		btnModify = new JButton(); 
    		btnSave = new JButton();
    		btnSearch = new JButton();
    		
    		getContentPane().setLayout(new FlowLayout());
    		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    		
    		// add shapesJPanel to frame    
    		ShapesJPanel logo = new ShapesJPanel();
    		logo.setPreferredSize(new Dimension(200,200));
    		getContentPane().add( logo );
    
    		// place textFields and labels
    		
    		//artist
    		artistLabel.setText("Artist"); 
    		getContentPane().add(artistLabel); 
    
    		artistField.setMinimumSize(new Dimension(70,20)); 
    		artistField.setPreferredSize(new Dimension(70,20));
    		getContentPane().add(artistField); 
    		
    		// cd name
    		cdNameLabel.setText("CD Name"); 
    		getContentPane().add(cdNameLabel); 
    
    		cdNameField.setMinimumSize(new Dimension(70,20)); 
    		cdNameField.setPreferredSize(new Dimension(70,20));
    		getContentPane().add(cdNameField);
    		
    		// copies in stock
    		nstockLabel.setText("Copies In Stock"); 
    		getContentPane().add(nstockLabel); 
    
    		nstockField.setMinimumSize(new Dimension(5,20)); 
    		nstockField.setPreferredSize(new Dimension(5,20));
    		getContentPane().add(nstockField); 
    		
    		//price of cd
    		priceLabel.setText("Price: $"); 
    		getContentPane().add(priceLabel); 
    
    		priceField.setMinimumSize(new Dimension(20,20)); 
    		priceField.setPreferredSize(new Dimension(20,20));
    		getContentPane().add(priceField); 
    		
    		//item number of cd
    		itemLabel.setText("Item Number"); 
    		getContentPane().add(itemLabel); 
    
    		itemField.setMinimumSize(new Dimension(5,20)); 
    		itemField.setPreferredSize(new Dimension(5,20));
    		getContentPane().add(itemField); 
    		
    
    
    		// add listeners
    		
    		btnAdd.setText("Add");
    		btnAdd.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnAdd);
    		 
    		// PREVIOUS
    		btnPrev.setText("Previous");
    		btnPrev.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnPrevActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnPrev);
    		
    		// NEXT
    		btnNext.setText("Next");
    		btnNext.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnNextActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnNext);
    		
    		// SEARCH
    		btnSearch.setText("Search");
    		btnSearch.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnSearch);
    		
    		// FIRST
    		btnFirst.setText("First");
    		btnFirst.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnFirstActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnFirst);
    		
    		// LAST
    		btnLast.setText("Last");
    		btnLast.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnLastActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnLast);
    				
    		// MODIFY
    		btnModify.setText("Modify");
    		btnModify.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnModifyActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnModify);
    					
    		// SAVE
    		btnSave.setText("Save");
    		btnSave.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnSave);
    		
    		// DELETE
    		btnDel.setText("Delete");
    		btnDel.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnDeleteActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnDel);
    		
    		
    		// new Jlist model
    		listModel = new DefaultListModel();
    		Inventorylist.setModel(listModel);
    		
    		jScrollPanel.setViewportView(Inventorylist);
    		
    		getContentPane().add(jScrollPanel);
    		
    		pack();
    	}// close
    	
    			
    		private void btnAddActionPerformed(ActionEvent evt)
    		{
    			// Create cd to add
    			CdwArtist newCD = new CdwArtist();
    			newCD.setArtist(artistField.getText());
    			newCD.setName(cdNameField.getText());	
    			newCD.setItemno(Integer.parseInt(itemField.getText()));
    			newCD.setNstock(Integer.parseInt(nstockField.getText()));
    			newCD.setPrice(Float.parseFloat(priceField.getText()));
    			
    			// Add cd to list
    			listModel.addElement(newCD);
    			currCD = listModel.size()-1;  // sets currCD to added index
    			
    			
    			// Clear the text fields after add
    			artistField.setText(null);
    			cdNameField.setText(null);	
    			itemField.setText(null);
    			nstockField.setText(null);
             priceField.setText(null);
    	
    			}// end ADD
    		
    		private void btnPrevActionPerformed(ActionEvent evt)
    		{
    			// Grab Previous cd 
    			if (--currCD<0) currCD = listModel.size()-1;
    			CdwArtist newCD = (CdwArtist) listModel.get( currCD );
    			
    
    			artistField.setText(newCD.getArtist());
    			cdNameField.setText(newCD.getName());	
    			itemField.setText(String.valueOf(newCD.getItemno()));
    			nstockField.setText(String.valueOf(newCD.getNstock()));
    			priceField.setText(formatter.format(newCD.getPrice()));
    					
    			
    			}// end PREV
    			
    				private void btnNextActionPerformed(ActionEvent evt)
    			{
    			// Grab Next cd 
    			if (++currCD >= listModel.size()) currCD= 0;
    			CdwArtist newCD = (CdwArtist) listModel.get( currCD );
    			
    
    			artistField.setText(newCD.getArtist());
    			cdNameField.setText(newCD.getName());	
    			itemField.setText(String.valueOf(newCD.getItemno()));
    			nstockField.setText(String.valueOf(newCD.getNstock()));
    			priceField.setText(formatter.format(newCD.getPrice()));
    					
    			
    			}// end NEXT
    			
    			
    				private void btnFirstActionPerformed(ActionEvent evt)
    			{
    			// Grab First cd 
    			CdwArtist newCD = (CdwArtist) listModel.get(0);
    			currCD = 0;
    				
    			artistField.setText(newCD.getArtist());
    			cdNameField.setText(newCD.getName());	
    			itemField.setText(String.valueOf(newCD.getItemno()));
    			nstockField.setText(String.valueOf(newCD.getNstock()));
    			priceField.setText(formatter.format(newCD.getPrice()));
    					
    			
    			}// end FIRST
    			
    			
    				private void btnLastActionPerformed(ActionEvent evt)
    			{
    			// Grab Last cd 
    			CdwArtist newCD = (CdwArtist) listModel.lastElement();
    			currCD = listModel.size()-1;
    			
    
    			artistField.setText(newCD.getArtist());
    			cdNameField.setText(newCD.getName());	
    			itemField.setText(String.valueOf(newCD.getItemno()));
    			nstockField.setText(String.valueOf(newCD.getNstock()));
    			priceField.setText(formatter.format(newCD.getPrice()));
    					
    			
    			}// end LAST
    			
    				private void btnDeleteActionPerformed(ActionEvent evt)
    			{
    			// Delete cd 
    			listModel.remove(currCD);
    				
    			
    			// Clear the text fields after delete
    			artistField.setText(null);
    			cdNameField.setText(null);	
    			itemField.setText(null);
    			nstockField.setText(null);
             priceField.setText(null);
    					
    			
    			}// end DELETE
    			
    				private void btnModifyActionPerformed(ActionEvent evt)
    			{
    			// Modify cd
    			listModel.remove(currCD);
    			
    			// Create cd to add
    			CdwArtist newCD = new CdwArtist();
    			newCD.setArtist(artistField.getText());
    			newCD.setName(cdNameField.getText());	
    			newCD.setItemno(Integer.parseInt(itemField.getText()));
    			newCD.setNstock(Integer.parseInt(nstockField.getText()));
    			newCD.setPrice(Float.parseFloat(priceField.getText()));
    			
    			// Add cd to list
    			listModel.addElement(newCD);
    			currCD = listModel.size()-1;  // sets currCD to added index
    			
    			
    			// Clear the text fields after add
    			artistField.setText(null);
    			cdNameField.setText(null);	
    			itemField.setText(null);
    			nstockField.setText(null);
             priceField.setText(null);
    					
    			
    			}// end Modify
    			
    			// Search the Name Field
    			cdNameField.addCaretListener(new CaretListener()
    			{
    			public void caretUpdate(CaretEvent e)
    				{
    				JTextField f = (JtextField)e.getSource();
    				final String s = f.getText();
    			 
    			
    		// run it
    		public static void main(String args[])
    		{
    		JFrame frame = new JFrame( "CD Inventory Logo" );
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    
         	java.awt.EventQueue.invokeLater(new Runnable()
    			{
    			public void run()
    				{
    				new Inventory2().setVisible(true);
    			   }
    			});
    		}
    			
    } // close class
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Don't allow the user to enter that (integer) key him/herself. Users are stupid
    beings that make mistakes all the time. Have you had a look at the Bitset
    class yet? I might come in handy.

    kind regards,

    Jos

    Comment

    • no1zson
      New Member
      • Jul 2007
      • 38

      #3
      I did. It is what I thought of useing, but the API just confuses me.
      I do not yet understand how to use the API properly, so I have been scanning the internet for code examples of one that is actually being used, but I cannot find a model to try and use to set mine up.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by no1zson
        I did. It is what I thought of useing, but the API just confuses me.
        It just allows you to set bits or reset them; either single bits or a range of them.
        You can also go fancy and 'or', 'and', 'xor' and whatever with two entire bit sets.
        You just need the simple stuff: get the first bit that wasn't set to true and set
        a bit to true or false. Compare it with a boolean[] array except that a BitSet is
        more clever than that.

        kind regards,

        Jos

        Comment

        • no1zson
          New Member
          • Jul 2007
          • 38

          #5
          wow. Now I feel dumb. I know nothing about arrays, and boolean is just a term to me at this point for true or false.

          I understand the basic concept, but have no idea how to code it.

          Am I reformatting the field? Am I creating a whole new field? Am I creating this bit and then applying it to my itemno field?

          I am lost.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by no1zson
            wow. Now I feel dumb. I know nothing about arrays, and boolean is just a term to me at this point for true or false.

            I understand the basic concept, but have no idea how to code it.

            Am I reformatting the field? Am I creating a whole new field? Am I creating this bit and then applying it to my itemno field?

            I am lost.
            Read all about that BitSet class and judge for yourself whether you can use it
            or not; maybe my suggestion was all wrong. You won't know until you've understood
            what that set is all about ;-)

            kind regards,

            Jos

            Comment

            • no1zson
              New Member
              • Jul 2007
              • 38

              #7
              I have read it, and I do think it will help, but reading about it does not show me how to code it in to my existing program. That is what I do not understand.

              I understand that you do not wish to just hand out code,

              but could you show code examples of what I might try? I have never seen this implemented anywhere, it is hard for me to see how I would put it in action with what I already have.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by no1zson
                I have read it, and I do think it will help, but reading about it does not show me how to code it in to my existing program. That is what I do not understand.

                I understand that you do not wish to just hand out code,

                but could you show code examples of what I might try? I have never seen this implemented anywhere, it is hard for me to see how I would put it in action with what I already have.
                There's a saying: "code to the interface, not to the implementation" . You want a
                'thing' that gives you a unique integer number when you ask for it and you can
                return a number (previously given to you by that 'thing') telling it that it can be
                used again in the future if you ask for another number again.

                Those numbers are your primary keys for your CD collection.

                Here goes:

                [code=java]
                public interface PrimaryKeyGener ator {
                public int give();
                public void take();
                }
                [/code]

                If you pass a PrimaryKeyGener ator (an interface!) to your CD collection at
                construction time (store it as a member variable), you can use it all over the
                place, i.e. when you insert a new CD you ask it to give() you a number; when
                you delete a CD you let that object take() it back.

                You should be able to program and compile your CD collection class using this
                interface; of course it won't run (yet) because there is no implementation of this
                interface yet.

                Here's a stupid implementation: i.e. it generates the numbers 0, 1, 2 ... and
                it doesn't do anything when you make it take() a number back again. You
                obviously don't want this implementation as a final implementation but it is
                enough to get you started. We'll implement a clever PrimaryKeyGener ator
                later when you understand that BitSet API. Here's the stupid interface implementation:

                [code=java]
                public class StupidPrimaryKe yGenerator implements PrimaryKeyGener ator {
                private int key;
                public synchronized int give() { return key++; }
                public void take() { }
                }
                [/code]

                kind regards,

                Jos

                Comment

                • no1zson
                  New Member
                  • Jul 2007
                  • 38

                  #9
                  OK, that is an explaination I THINK I understand.

                  So, I do not want the user entering anything in to my itemField, I should probably just set editable to false and be done with it right off the bat.

                  I should then impliment the public int give(); every time a cd is added, which stupidkeygenera tor will give the next available number?

                  Is that about the long and short of it, or am I twisted?

                  If all that is right, my only remaining question (at the moment) would be how does int give() know to give its number to itemField?
                  should I not also have to change the way the field is built and initialize?

                  currently I have this:

                  Code:
                  private JTextField itemField;
                  and
                  itemField = new JTextField(4);
                  itemField.setEditable(true);
                  and
                  newCD.setItemno(Integer.parseInt(itemField.getText()));
                  when a cd is added
                  If I am to code the interface, and not the implementation, will not most of that need to change also?

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by no1zson
                    OK, that is an explaination I THINK I understand.

                    So, I do not want the user entering anything in to my itemField, I should probably just set editable to false and be done with it right off the bat.

                    I should then impliment the public int give(); every time a cd is added, which stupidkeygenera tor will give the next available number?

                    Is that about the long and short of it, or am I twisted?

                    If all that is right, my only remaining question (at the moment) would be how does int give() know to give its number to itemField?
                    should I not also have to change the way the field is built and initialize?

                    currently I have this:

                    Code:
                    private JTextField itemField;
                    and
                    itemField = new JTextField(4);
                    itemField.setEditable(true);
                    and
                    newCD.setItemno(Integer.parseInt(itemField.getText()));
                    when a cd is added
                    If I am to code the interface, and not the implementation, will not most of that need to change also?
                    But now in that class you have a KeyGenerator object, so instead of setting itemNo with value entered by the user, you simply call the give method and use the number that it has generated as the itemNo

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by no1zson
                      OK, that is an explaination I THINK I understand.

                      So, I do not want the user entering anything in to my itemField, I should probably just set editable to false and be done with it right off the bat.

                      I should then impliment the public int give(); every time a cd is added, which stupidkeygenera tor will give the next available number?
                      Erm, you should just invoke the give() method if you want a new primary key
                      for a new CD. The method is implemented by the implementation of that interface
                      (here it's the stupid implementation which you pass to the constructor of your
                      CD collection object just once).

                      Originally posted by no1zson
                      Is that about the long and short of it, or am I twisted?
                      Yep, I think it's right: you pass a key generator to the constructor of your CD
                      collection class and the methods of your class use that thing when they want
                      a new number or if they want to give a number back to it.

                      Originally posted by no1zson
                      If all that is right, my only remaining question (at the moment) would be how does int give() know to give its number to itemField?
                      should I not also have to change the way the field is built and initialize?
                      It doesn't know that: all it does is give a new unique number; your methods
                      are supposed to stick that number in a text field or in some other place.

                      Originally posted by no1zson
                      currently I have this:

                      Code:
                      private JTextField itemField;
                      and
                      itemField = new JTextField(4);
                      itemField.setEditable(true);
                      and
                      newCD.setItemno(Integer.parseInt(itemField.getText()));
                      when a cd is added
                      If I am to code the interface, and not the implementation, will not most of that need to change also?
                      Nope, don't parse anything from that textfield; use that number the generator
                      give()s you. It's a unique number and that's what you want. If you want to display
                      the data given a currCD, simply retrieve it from your JList and display it in the
                      text field (the user can't edit it anyway).

                      kind regards,

                      Jos

                      Comment

                      • no1zson
                        New Member
                        • Jul 2007
                        • 38

                        #12
                        OK. after two hours, several curse words I think I am pretty close.
                        I tried to take all that and weave it into the fabric of my current code.
                        This is what I have.
                        I took the generator and put it into my primary Inventory class
                        Code:
                        public interface PrimaryKeyGenerator
                        	{
                        	public int give();
                        	public void take();
                        	}
                        No compile issues so I moved forward.
                        I then took the code from your implementor class in put it in my objects class
                        cdwartist where I already have several object defined.
                        Code:
                         // returns indivudual inventory value for a disk
                         public float getTotal()
                         {
                         return(price * nstock)+((price * nstock)* restock);
                         }	
                         
                         // generates automotic number for itemno
                         public synchronized int give()
                         {
                         return key++;
                         }
                         // takes back number from itemno 
                         public void take()
                         {
                         }
                        and
                        Code:
                         private float invtotal; // total inventory value of all cds
                         private int key; // generator for itemno field
                        No compile issues there, so I think I am getting somewhere. I move back to my primary inventory class to make the itemno field use this key everytime a cd is added ...
                        Code:
                        	// Create cd to add
                        			CdwArtist newCD = new CdwArtist();
                        			newCD.setArtist(artistField.getText());
                        			newCD.setName(cdNameField.getText());
                        			newCD.setItemno(give());	
                        			//newCD.setItemno(Integer.parseInt(itemField.getText()));
                        			newCD.setNstock(Integer.parseInt(nstockField.getText()));
                        			newCD.setPrice(Float.parseFloat(priceField.getText()));
                        I left the old one in (commented out) until I get this one working, but this is where I hit a snag, and it errors saying
                        Inventory2.java :289: cannot find symbol
                        symbol : method give()
                        location: class Inventory2
                        newCD.setItemno (give());


                        I think I am close but just missing a simple step somewhere ... any suggestions?

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by no1zson
                          OK. after two hours, several curse words I think I am pretty close.
                          I tried to take all that and weave it into the fabric of my current code.
                          You did what? You should have made at least three separate files:

                          1) PrimaryKeyGener ator.java
                          2) StupidPrimaryKe yGenerator.java
                          3) CDInventory.jav a

                          and your add and delete functionality should just have invoked the give() and
                          take() methods. The give() call on the PrimaryKeyGener ator should be the
                          substitute for parsing that text field.

                          kind regards,

                          Jos

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Object-oriented programming tries to run away from all that weaving and lumping together of functionality.
                            Code that achieves different functionality should be kept as separate as possible so that different functionalities can be worked on at different times (and possibly by different people too).
                            In your case the unique number generating functionality should not be mixed with the rest of the inventory management code. Always be on the look out for this when designing your programs. If you require new functionality that consists of many actions(e.g generation and management of primary keys) you must add a new object (read class) to your system that can do this functionality and implements the required methods without affecting the rest of your code.

                            Comment

                            • no1zson
                              New Member
                              • Jul 2007
                              • 38

                              #15
                              OK, my post was a little ambiguous.
                              I did use three classes, two of them I already had.
                              the first, as you pointed out was Inventory.java (my application)
                              I initialized the components
                              Code:
                              public interface PrimaryKeyGenerator
                              		{
                              		public int give();
                              		public void take();
                              		}
                              the second was simpleprimaryke ygenerator.java
                              here is pretty self explainatory, i put
                              public class SimplePrimaryKe yGenerator implements PrimaryKeyGener ator
                              Code:
                              {
                              private int key;
                              
                              	public synchronized int give()
                              	{
                              	return key++;
                              	}
                              	
                              	public void take()
                              	{
                              	}
                              } // end class
                              and the third was cdwartist.java that I already had, and where I define many of my objects. I put
                              Code:
                              // generates automotic number for itemno
                               public synchronized int give()
                               {
                               return key++;
                               }
                               // takes back number from itemno 
                               public void take()
                               {
                               }
                              Is that not acceptable? I did not make a new class for each one because I thought it would be better to group like objects.

                              Comment

                              Working...