RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting

First JLIST, used with GUI Inventory

Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: First JLIST, used with GUI Inventory

  #24  
Jul 26th, 2007
        private void btnAddActionPerformed(ActionEvent evt)
        {
            // Create cd to add
            currCD++;
            artistField.getText(currCD.getArtist());
            cdNameField.getText(currCD.getcdName());    
            Integer.parseInt(itemField.getText(currCD.getitemno()));
            Integer.parseInt(nstockField.getText(currCD.getNstock()));
            Float.parseFloat(priceField.getText(currCD.getPrice()));
            Float.parseFloat(valueField.getText(currCD.getValue()));
            Float.parseFloat(totalField.getText(currCD.getTotal()));
            Float.parseFloat(rstkField.getText(currCD.getrestock()));    
            
            // Add cd to list
            
            
            listModel.addElement(currCD);
Ok, I see. That was not the "currentCD" reference I was talking about. I meant a persistent one that you kept at the class level.
You do need to create a CdwArtist object there to add it to the list. Perhaps we should just call that "newCD" to avoid confusion. Also, since the index is 0 based, it would be easier to initialize currCD with a value of -1 when you declare it, so your add code would be:
        private void btnAddActionPerformed(ActionEvent evt)
        {
            // Create cd to add
            CdwArtist newCD = new CdwArtist();
            newCD.setArtist(artistField.getText());
            newCD.setCdName(cdNameField.getText());    
            newCD.setItemNo(Integer.parseInt(itemField.getText());
            
                        <snip other sets>

            // Add cd to list
            listModel.addElement(newCD);
            currCD = listModel.size()-1;    // set currCD to the index that was added
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:04 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC