Results 1 to 6 of 6
  1. #1
    Azzia is offline Member
    Join Date
    May 2008
    Location
    Ohio
    Posts
    20
    Rep Power
    0

    Default Reccomendations for GUI

    Hi again :(

    I have build my GUI but am now having some issues implementing the code to make it work. Basically, our text book is rediculous and I can't seem to understand what it is I need to do. I have looked at samples but apparently i need it explained to me like a dummy.

    Basically, my questions is how do I create a GUI for a project I have already coded? I have my inventory project which has all my code and works without the GUI. Then i have a complete different project that holds my GUI. How do I mesh them together to get them to work. That is my main concern.

    Java Code:
    /*
     * InventoryGUI.java
     *
     * Created on May 28, 2008, 4:44 PM
     */
    
    package learn;
    
    /**
     *
     * @author  MKAY
     */
    public class InventoryGUI extends javax.swing.JFrame {
        
        /** Creates new form InventoryGUI */
        public InventoryGUI() {
            initComponents();
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            itemNum = new javax.swing.JLabel();
            itemNam = new javax.swing.JLabel();
            stockNum = new javax.swing.JLabel();
            price = new javax.swing.JLabel();
            ttlValue = new javax.swing.JLabel();
            numField = new javax.swing.JTextField();
            namField = new javax.swing.JTextField();
            stockField = new javax.swing.JTextField();
            priceField = new javax.swing.JTextField();
            valueField = new javax.swing.JTextField();
            add = new javax.swing.JButton();
            quit = new javax.swing.JButton();
            calculateTtlValue = new javax.swing.JButton();
            ttlValueField = new javax.swing.JTextField();
            prevProduct = new javax.swing.JButton();
            nextProduct = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Inventory Program");
    
            itemNum.setText("Product Number");
    
            itemNam.setText("Product Name");
    
            stockNum.setText("Units in Stock");
    
            price.setText("Price per Unit");
    
            ttlValue.setText("Value of product");
    
            numField.setText("jTextField1");
    
            namField.setText("jTextField2");
    
            stockField.setText("jTextField3");
    
            priceField.setText("jTextField4");
    
            valueField.setText("jTextField5");
    
            add.setText("Add ");
            add.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    addActionPerformed(evt);
                }
            });
    
            quit.setText("Cancel");
            quit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    quitActionPerformed(evt);
                }
            });
    
            calculateTtlValue.setText("Total Value");
            calculateTtlValue.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calculateTtlValueActionPerformed(evt);
                }
            });
    
            ttlValueField.setText("jTextField6");
    
            prevProduct.setText("<<Previous");
            prevProduct.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    prevProductActionPerformed(evt);
                }
            });
    
            nextProduct.setText("Next>>");
            nextProduct.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    nextProductActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(itemNum)
                                        .addComponent(itemNam)
                                        .addComponent(stockNum)
                                        .addComponent(price)
                                        .addComponent(ttlValue))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 219, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(valueField)
                                        .addComponent(priceField)
                                        .addComponent(stockField)
                                        .addComponent(namField)
                                        .addComponent(numField, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                                        .addComponent(ttlValueField, javax.swing.GroupLayout.Alignment.TRAILING)))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(prevProduct)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(nextProduct, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(63, 63, 63)
                                    .addComponent(quit)
                                    .addGap(18, 18, 18)
                                    .addComponent(add)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                        .addComponent(calculateTtlValue))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(numField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(itemNum))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(itemNam)
                        .addComponent(namField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(stockNum)
                        .addComponent(stockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(price)
                        .addComponent(priceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(ttlValue)
                        .addComponent(valueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(calculateTtlValue)
                        .addComponent(ttlValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(prevProduct)
                                    .addComponent(nextProduct))
                                .addContainerGap())
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(quit)
                                .addContainerGap()))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(18, 18, 18)
                            .addComponent(add)
                            .addContainerGap())))
            );
    
            pack();
        }// </editor-fold>
    
        private void nextProductActionPerformed(java.awt.event.ActionEvent evt) {
            // skip to the next product
    }
    
        private void calculateTtlValueActionPerformed(java.awt.event.ActionEvent evt) {
            // calculate total inventory value
        }
    
        private void prevProductActionPerformed(java.awt.event.ActionEvent evt) {
            // go back to previous item
        }
    
        private void addActionPerformed(java.awt.event.ActionEvent evt) {
            // add a new item
        }
    
        private void quitActionPerformed(java.awt.event.ActionEvent evt) {
            // Quit the program
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new InventoryGUI().setVisible(true);
                }
            });
        }
        
        // Variables declaration - do not modify
        private javax.swing.JButton add;
        private javax.swing.JButton calculateTtlValue;
        private javax.swing.JLabel itemNam;
        private javax.swing.JLabel itemNum;
        private javax.swing.JTextField namField;
        private javax.swing.JButton nextProduct;
        private javax.swing.JTextField numField;
        private javax.swing.JButton prevProduct;
        private javax.swing.JLabel price;
        private javax.swing.JTextField priceField;
        private javax.swing.JButton quit;
        private javax.swing.JTextField stockField;
        private javax.swing.JLabel stockNum;
        private javax.swing.JLabel ttlValue;
        private javax.swing.JTextField ttlValueField;
        private javax.swing.JTextField valueField;
        // End of variables declaration
        
    }
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package inventory;
    
    /**
     *
     * @author MKAY
     */
    
    public class Inventory
    {
        private String itemName; // variable that stores the cartridge name
        private int itemNumber; // variable that stores the item number
        private int invStock; // variable that stores the quantity in stock
        private double itemPrice; // variable that stores the cartridge price
        public double getValue;
        public String calculateInventoryValue;
    
    public Inventory(String name, int number, int stock, double price)
        {
        itemName = name;
        itemNumber = number;
        invStock = stock;
        itemPrice = price;
        }
    public static void main(String[] args) {
    }
    
    public void setItemName(String name) // Method to set the item name
            
        {
        this.itemName = name;
        }
    
    public String getItemName() // Method to get the item name
            
        {
        return itemName;
        } 
    public void setItemNumber(int number) // Method to set the item number
            
        {
        this.itemNumber = number;
        }
    
    public int getItemNumber() // Method to get the item number
            
        {
        return itemNumber;
        }
    
    public void setInvStock(int stock) // Method to set the stock in stock
            
        {
        invStock = stock;
        }
    
    public int getInvStock() // Method to get the stock in stock
            
        {
        return invStock;
        }
    
    public void setItemPrice(double price) // Method to set the item price
            
        {
        this.itemPrice = price;
        }
    
    public double getItemPrice() // Method to get the item price
            
        {
        return itemPrice;
        }
    
    public double getCalculateInventoryValue() // Method to calculate the value of the inventory
            
        {
        return (double) itemPrice * invStock;
        }
    
    public double getValue()
    {
     return (double) itemPrice * invStock;
    }
    
        
    
    public int compareTo(Object o)
    {
            Inventory p = null;
            try
     {
            p = (Inventory) o;
     }
    
        catch (ClassCastException cE)
     {
            cE.printStackTrace();
     }
    
        return itemName.compareTo(p.getItemName());
    }
    
    public String toString()
            
        {
        return String.format("%s: %s\n %s: %.2f\n %s: %.2f\n %s: %.2f", 
                "Item name",getItemName(), 
                "Item Number",getItemNumber(),
                "Stock",getInvStock(),
                "Item Price",getItemPrice(), 
                "Total Inventory Value",getCalculateInventoryValue());
        }
    
        private void calculateInventoryValue() {
            throw new UnsupportedOperationException("Not yet implemented");
        }
    } //end class Product
    
    class DVD extends Inventory
    {
    private double reStockingFee;
    
    public DVD(String itemName, int itemNumber, int invStock, double itemPrice, double reStockingFee) 
    {
    super (itemName, itemNumber, invStock, itemPrice);
    this.reStockingFee = reStockingFee;
    } 
        @Override
    public double getItemPrice() //returns the value of the inventory, plus the restocking fee
    {
    return super.getItemPrice() + reStockingFee;
    }
    public String toString() 
    {
    return new StringBuffer().append("Price:$ " + super.getItemPrice()).append(" With RestockingFee: $ " + getItemPrice()).toString();
    }
    
    } // end class Product
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package inventory;
    
    /**
     *
     * @author MKAY
     */
    
    public class Inventory3
    
    {
    public static void main(String[] args)
        {
            double reStockingFee = 0.05; 
    
            //Declare and initialize the inventory array
            Inventory[] inventory = new Inventory[5]; //Array variables
    
            inventory[0] = new Inventory("Robin Hood", 1001, 3, 10.95);
            inventory[1] = new Inventory("NCIS Season 4", 1002, 2, 44.11);
            inventory[2] = new Inventory("The Departed", 1003, 4, 22.45);
            inventory[3] = new Inventory("A Man Apart", 1004, 16, 18.99);
            inventory[4] = new Inventory("Gone with the Wind", 1005, 14, 13.54);
    
            Inventory temp[] = new Inventory[1];
            
            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];
                }
            }
        }
    
    
            System.out.println("Inventory Program for DVD's"); //display header
            System.out.println(); // blank line
            System.out.println(); // blank line
            for(int i = 0; i < inventory.length; i++)
            {
                System.out.println("Item Number: " + inventory[i].getItemNumber());
                System.out.println("Item Name: " + inventory[i].getItemName());
                System.out.println("Inventory On Hand: " + inventory[i].getInvStock());
                System.out.println("Item Price: $" + inventory[i].getItemPrice());
                System.out.println("Value of Inventory: $" + inventory[i].getValue());
    
                System.out.println("Restock Fee: $" + (inventory[i].getInvStock() * inventory[i].getItemPrice()) * 0.05);
                System.out.println(); 
    
            }        
        } 
    
    } //End class Inventory3


    There's everything I have so far. Maybe I am just too frustrated with this to understand but I am having a very difficult time.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    Well, without running any of your code I can give you the basic idea.
    You have the gui be the "main" startup that is called when the app starts.
    The the gui gets the data to display from your report class. Sortof like this:
    Java Code:
     
    Inventory inv = new Inventory();
    List stufftoDisplay=inv.getReport();
    So get move the code from the main method in Inventory and put it in another public class and then make a constructor in Inventory so it can be called from the GUI class.
    HTH

  4. #4
    Azzia is offline Member
    Join Date
    May 2008
    Location
    Ohio
    Posts
    20
    Rep Power
    0

    Default

    Yes, I am doing this with Netbeans. Here is what I have so far just from playing around with it a bit. Of course it doesn't work but I think I am on the right track. Still trying to figure out where to put in the constructor and how to call it. Seems everything I do isn't correct.

    EDIT: So I am guessing that Inventory 3 above is what will be populating my fields so what i can't seem to grasp is how to call that and get it to work in my GUI.

    Java Code:
    public class InventoryGUI extends javax.swing.JFrame {
        
        
        
        /** Creates new form InventoryGUI */
        public InventoryGUI() {
            initComponents();
            //Declare and initialize the inventory array
            Inventory[] inventory = new Inventory[5]; //Array variables
    
            inventory[0] = new Inventory("Robin Hood", 1001, 3, 10.95);
            inventory[1] = new Inventory("NCIS Season 4", 1002, 2, 44.11);
            inventory[2] = new Inventory("The Departed", 1003, 4, 22.45);
            inventory[3] = new Inventory("A Man Apart", 1004, 16, 18.99);
            inventory[4] = new Inventory("Gone with the Wind", 1005, 14, 13.54);
    
            Inventory temp[] = new Inventory[1];
            
            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];
                }
            }
        }
    
    
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            itemNum = new javax.swing.JLabel();
            itemNam = new javax.swing.JLabel();
            stockNum = new javax.swing.JLabel();
            price = new javax.swing.JLabel();
            ttlValue = new javax.swing.JLabel();
            numField = new javax.swing.JTextField();
            namField = new javax.swing.JTextField();
            stockField = new javax.swing.JTextField();
            priceField = new javax.swing.JTextField();
            valueField = new javax.swing.JTextField();
            add = new javax.swing.JButton();
            quit = new javax.swing.JButton();
            calculateTtlValue = new javax.swing.JButton();
            ttlValueField = new javax.swing.JTextField();
            prevProduct = new javax.swing.JButton();
            nextProduct = new javax.swing.JButton();
            firstProduct = new javax.swing.JButton();
            lastProduct = new javax.swing.JButton();
            searchProduct = new javax.swing.JButton();
            displaySearch = new javax.swing.JTextField();
            saveProduct = new javax.swing.JButton();
            deleteProduct = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Inventory Program");
    
            itemNum.setText("Product Number");
    
            itemNam.setText("Product Name");
    
            stockNum.setText("Units in Stock");
    
            price.setText("Price per Unit");
    
            ttlValue.setText("Value of product");
    
            numField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    numFieldActionPerformed(evt);
                }
            });
    
            namField.setText("0");
            namField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    namFieldActionPerformed(evt);
                }
            });
    
            stockField.setText("jTextField3");
            stockField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    stockFieldActionPerformed(evt);
                }
            });
    
            priceField.setText("jTextField4");
            priceField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    priceFieldActionPerformed(evt);
                }
            });
    
            valueField.setText("jTextField5");
            valueField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    valueFieldActionPerformed(evt);
                }
            });
    
            add.setText("Add ");
            add.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    addActionPerformed(evt);
                }
            });
    
            quit.setText("Cancel");
            quit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    quitActionPerformed(evt);
                }
            });
    
            calculateTtlValue.setText("Total Value");
            calculateTtlValue.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calculateTtlValueActionPerformed(evt);
                }
            });
    
            ttlValueField.setText("jTextField6");
    
            prevProduct.setText("<<Previous");
            prevProduct.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    prevProductActionPerformed(evt);
                }
            });
    
            nextProduct.setText("Next>>");
            nextProduct.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    nextProductActionPerformed(evt);
                }
            });
    
            firstProduct.setText("<First");
            firstProduct.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    firstProductActionPerformed(evt);
                }
            });
    
            lastProduct.setText("Last>");
    
            searchProduct.setText("Search");
    
            displaySearch.setText("jTextField1");
    
            saveProduct.setText("Save");
    
            deleteProduct.setText("Delete");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(itemNum)
                                        .addComponent(itemNam)
                                        .addComponent(stockNum)
                                        .addComponent(price)
                                        .addComponent(ttlValue))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 212, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(valueField)
                                        .addComponent(priceField)
                                        .addComponent(stockField)
                                        .addComponent(namField)
                                        .addComponent(numField, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(searchProduct, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(firstProduct, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(prevProduct, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(displaySearch)
                                        .addComponent(lastProduct, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(nextProduct, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                                    .addGap(28, 28, 28)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(saveProduct, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                                        .addComponent(quit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))
                                    .addGap(12, 12, 12)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(add, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                                        .addComponent(deleteProduct, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(187, 187, 187)
                            .addComponent(calculateTtlValue)
                            .addGap(27, 27, 27)
                            .addComponent(ttlValueField, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(numField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(itemNum))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(itemNam)
                        .addComponent(namField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(stockNum)
                        .addComponent(stockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(price)
                        .addComponent(priceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(ttlValue)
                        .addComponent(valueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(47, 47, 47)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(nextProduct)
                        .addComponent(prevProduct)
                        .addComponent(quit)
                        .addComponent(add))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(firstProduct)
                                .addComponent(lastProduct))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(searchProduct)
                                .addComponent(displaySearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(saveProduct)
                            .addComponent(deleteProduct)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ttlValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(calculateTtlValue))
                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>                        
    
        private void nextProductActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // skip to the next product
    }                                           
    
        private void calculateTtlValueActionPerformed(java.awt.event.ActionEvent evt) {                                                  
            // calculate total inventory value
        }                                                 
    
        private void prevProductActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // go back to previous item
        }                                           
    
        private void addActionPerformed(java.awt.event.ActionEvent evt) {                                    
            numField.setText("");
            namField.setText("");
            stockField.setText("");
            priceField.setText("");
            valueField.setText("");
        }                                   
    
        private void quitActionPerformed(java.awt.event.ActionEvent evt) {                                     
            System.exit(0);
        }                                    
    
        private void stockFieldActionPerformed(java.awt.event.ActionEvent evt) {                                           
            stockField.setText("" + inventory[].getInvStock );
        }                                          
    
        private void numFieldActionPerformed(java.awt.event.ActionEvent evt) {                                         
             numField.setText(""+ inventory[].getItemNumber());
        }                                        
    
        private void namFieldActionPerformed(java.awt.event.ActionEvent evt) {                                         
            namField.setText("" + inventory[].getItemName());
        }                                        
    
        private void priceFieldActionPerformed(java.awt.event.ActionEvent evt) {                                           
            priceField.setText(""+ inventory[].getItemPrice());
        }                                          
    
        private void valueFieldActionPerformed(java.awt.event.ActionEvent evt) {                                           
            valueField.setText(""+ inventory[].getValue());
        }                                          
        
        private void firstProductActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new InventoryGUI().setVisible(true);
                }
            });
        }
        
        // Variables declaration - do not modify                     
        private javax.swing.JButton add;
        private javax.swing.JButton calculateTtlValue;
        private javax.swing.JButton deleteProduct;
        private javax.swing.JTextField displaySearch;
        private javax.swing.JButton firstProduct;
        private javax.swing.JLabel itemNam;
        private javax.swing.JLabel itemNum;
        private javax.swing.JButton lastProduct;
        private javax.swing.JTextField namField;
        private javax.swing.JButton nextProduct;
        private javax.swing.JTextField numField;
        private javax.swing.JButton prevProduct;
        private javax.swing.JLabel price;
        private javax.swing.JTextField priceField;
        private javax.swing.JButton quit;
        private javax.swing.JButton saveProduct;
        private javax.swing.JButton searchProduct;
        private javax.swing.JTextField stockField;
        private javax.swing.JLabel stockNum;
        private javax.swing.JLabel ttlValue;
        private javax.swing.JTextField ttlValueField;
        private javax.swing.JTextField valueField;
        // End of variables declaration                   
        
    }
    Last edited by Azzia; 05-29-2008 at 10:18 PM.

  5. #5
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    I am getting a lot of compliation errors.
    First, your InventoryGui cannot even find the inventory variable. Set it like this:
    Java Code:
    Inventory[] inventory= new Inventory[5]; //Array variables
    
       /** Creates new form InventoryGUI */
       public InventoryGUI() {
           initComponents();
           //Declare and initialize the inventory array
           inventory[0] = new Inventory("Robin Hood", 1001, 3, 10.95);
          ....etc
    then starting at line 293 I am getting all kinds of errors on
    this sort of thing:
    Java Code:
    inventory[].getInvStock()
    You cannot do this.

  6. #6
    Azzia is offline Member
    Join Date
    May 2008
    Location
    Ohio
    Posts
    20
    Rep Power
    0

    Default

    I was trying several ways to try and make it work. It's amazing what this class expects from us but doesn't give us many examples. I myself have learned through source code rather than text book explinations so this is proving to be rather difficult. I see what you have done so let me give it a go. Thanks for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •