Adding a GUI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nexcompac
    New Member
    • May 2007
    • 22

    Adding a GUI

    Ok, I am working on an inventory program and this is where I am at thus far. I seem to be getting two errors that I can not figure out. I will post the errors at the end of the code.


    Code:
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    
    
    public class Inventory extends JFrame// Main class
    {
    
    
    	private JLabel prodNameLabel;
    	private JLabel numberLabel;
    	private JLabel unitLabel;
    	private JLabel priceLabel;
    	private JLabel featureLabel;
    	private JLabel valueLabel;
    	private JLabel rstkLabel;
    	private JLabel totalLabel;
    	private JTextField prodNameField;
    	private JTextField numberField;
    	private JTextField unitField;
    	private JTextField priceField;
    	private JTextField featureField;
    	private JTextField valueField;
    	private JTextField rstkField;
    	private JTextField totalField;
    	private JButton firstBtn;
    	private JButton prevBtn;
    	private JButton nextBtn;
    	private JButton lastBtn;
    	private JPanel buttonJPanel;
    	private JPanel fieldJPanel;
    	private JPanel fontJPanel;
    	private List<ProductAdd> nwProduct;
    	private int currProd = 0;
    	private double total; // variable for total inventory
    
    
    
    	public Inventory()
    	{
    		initComponents();
    	}
    
    	private void initComponents()
    	{
    		prodNameLabel = new JLabel("Product Name:");
    		numberLabel = new JLabel("Item Number:");
    		unitLabel = new JLabel("In Stock:");
    		priceLabel = new JLabel("Each Item Cost:");
    		featureLabel = new JLabel("Type of Item:");
    		valueLabel = new JLabel("Value of Item Inventory:");
    		rstkLabel = new JLabel("Cost to Re-Stock Item:");
    		totalLabel = new JLabel("Total Value of Inventory:");
    
    		firstBtn = new JButton("First");
    		prevBtn = new JButton("Previous");
    		nextBtn = new JButton("Next");
    		lastBtn = new JButton("Last");
    
    		prodNameField = new JTextField();
    		prodNameField.setEditable(false);
    		numberField = new JTextField();
    		numberField.setEditable(false);
    		unitField = new JTextField();
    		unitField.setEditable(false);
    		priceField = new JTextField();
    		priceField.setEditable(false);
    		featureField = new JTextField();
    		featureField.setEditable(false);
    		valueField = new JTextField();
    		valueField.setEditable(false);
    		rstkField = new JTextField();
    		rstkField.setEditable(false);
    		totalField = new JTextField();
    		totalField.setEditable(false);
    
    		prodNameLabel.setSize(200, 20);
    		numberLabel.setSize(200, 20);
    		unitLabel.setSize(200, 20);
    		priceLabel.setSize(200, 20);
    		featureLabel.setSize(200, 20);
    		valueLabel.setSize(200, 20);
    		rstkLabel.setSize(200, 20);
    		totalLabel.setSize(200, 20);
    
    		prodNameField.setSize(100, 20);
    		numberField.setSize(100, 20);
    		unitField.setSize(100, 20);
    		priceField.setSize(100, 20);
    		featureField.setSize(100, 20);
    		valueField.setSize(100, 20);
    		rstkField.setSize(100, 20);
    		totalField.setSize(100, 20);
    
    		buttonJPanel = new JPanel(); // set up panel
    		buttonJPanel.setLayout( new GridLayout(1, 4)); //set layout
    		// add buttons to buttonJPanel
    		buttonJPanel.add(firstBtn);
    		buttonJPanel.add(prevBtn);
    		buttonJPanel.add(nextBtn);
    		buttonJPanel.add(lastBtn);
    
    
    
        }
        public static void main( String args[])
        {
          product[] myProduct = new product[5];
          //Company[] myCompany = new Company[5];
    
            product p1 = new Company("Mad Dash", 20003, 5, 30, "EIDOS");
            product p2 = new Company("Fuzion Frenzy", 74512, 2, 10, "MicroSoft");
            product p3 = new Company("Time Splitters 2", 20009, 3, 45, "EIDOS");
            product p4 = new Company("Night Caster", 74522, 8, 5, "MicroSoft");
            product p5 = new Company("Lego Star Wars II", 32976, 1, 50, "LucasArts");
    
            myProduct[0] = p1;
            myProduct[1] = p2;
            myProduct[2] = p3;
            myProduct[3] = p4;
            myProduct[4] = p5;
    
            double totalValue = 0.0;
    
            for (int c=0; c < 5; c++)
            {
                totalValue = totalValue + myProduct[c].itemCalculate();
            }
    
            Arrays.sort(myProduct); // function used to sort arrays
    
            for(product p: myProduct)
            {
                System.out.println(p);
                System.out.println();
            }
           System.out.println("Total Inventory value is: $"+totalValue);
    
       } //end main
    
    } //end Inventory

    Here are the two errors that I recieve

    Code:
    C:\Users\Brian\Desktop\Java Inventory program\Inventory.java:35: cannot find symbol
    symbol  : class list
    location: class Inventory
    	private list<ProductAdd> nwProduct;
    	        ^
    C:\Users\Brian\Desktop\Java Inventory program\Inventory.java:35: cannot find symbol
    symbol  : class ProductAdd
    location: class Inventory
    	private list<ProductAdd> nwProduct;
    	             ^
    2 errors
    
    Tool completed with exit code 1
    Can not figure out why this will not compile... What am I missing.
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #2
    Originally posted by nexcompac
    C:\Users\Brian\ Desktop\Java Inventory program\Invento ry.java:35: cannot find symbol
    symbol : class list
    location: class Inventory
    private list<ProductAdd > nwProduct;
    ^
    C:\Users\Brian\ Desktop\Java Inventory program\Invento ry.java:35: cannot find symbol
    symbol : class ProductAdd
    location: class Inventory
    private list<ProductAdd > nwProduct;
    ^
    2 errors

    Tool completed with exit code 1


    Can not figure out why this will not compile... What am I missing.
    Hi,
    luk at ur first error...compile r is not able to find symbol *list*...I think it should be *List*.
    Same problem can be in second error also...check for ProductAdd..Is it the right name. check for spelling also..

    thanks and regards,
    madhoriya22

    Comment

    • nexcompac
      New Member
      • May 2007
      • 22

      #3
      I tried both ways with the capitols. Still got the same errors.

      Comment

      • madhoriya22
        Contributor
        • Jul 2007
        • 251

        #4
        Originally posted by nexcompac
        I tried both ways with the capitols. Still got the same errors.
        Hi,
        Where are you using this List<ProductAdd > nwProduct in ur program?

        thanks and regards,
        madhoriya22.

        Comment

        • praveen2gupta
          New Member
          • May 2007
          • 200

          #5
          Hi
          private List<ProductAdd > nwProduct declaration is wrong
          use following
          private List nwProduct;

          Comment

          • nexcompac
            New Member
            • May 2007
            • 22

            #6
            ok, changed that line of code to read what you sugested and here are the error codes.

            Code:
            C:\Users\Brian\Desktop\Java Inventory program\Inventory.java:35: reference to List is ambiguous, both class java.awt.List in java.awt and class java.util.List in java.util match
            	private List nwProduct;
            	        ^
            1 error
            
            Tool completed with exit code 1

            What is ment by where is my refrence?

            Comment

            • madhoriya22
              Contributor
              • Jul 2007
              • 251

              #7
              Originally posted by nexcompac
              ok, changed that line of code to read what you sugested and here are the error codes.

              Code:
              C:\Users\Brian\Desktop\Java Inventory program\Inventory.java:35: reference to List is ambiguous, both class java.awt.List in java.awt and class java.util.List in java.util match
              	private List nwProduct;
              	 ^
              1 error
               
              Tool completed with exit code 1

              What is ment by where is my refrence?
              Hi,
              where u have initialized ur List? Compiler is not able to differentiate that Is it a AWT List or util List.

              Thanks and regards,
              madhoriya22.

              Comment

              • nexcompac
                New Member
                • May 2007
                • 22

                #8
                Ok, so I removed the line to work backwards to move forward. Now, it complies but the GUI does not show up. When I run the program it goes to the comand prompt.

                Code:
                import java.util.*;
                import java.awt.*;
                import javax.swing.*;
                import java.awt.event.*;
                import javax.swing.JFrame; // provides basic window features
                import javax.swing.JLabel; // displays text and images
                import javax.swing.SwingConstants; // common constants used with Swing
                import javax.swing.Icon; // interface used to manipulate images
                import javax.swing.ImageIcon; // loads images
                
                
                
                public class Inventory extends JFrame// Main class
                {
                
                
                	private JLabel prodNameLabel;
                	private JLabel numberLabel;
                	private JLabel unitLabel;
                	private JLabel priceLabel;
                	private JLabel featureLabel;
                	private JLabel valueLabel;
                	private JLabel rstkLabel;
                	private JLabel totalLabel;
                	private JTextField prodNameField;
                	private JTextField numberField;
                	private JTextField unitField;
                	private JTextField priceField;
                	private JTextField featureField;
                	private JTextField valueField;
                	private JTextField rstkField;
                	private JTextField totalField;
                	private JButton firstBtn;
                	private JButton prevBtn;
                	private JButton nextBtn;
                	private JButton lastBtn;
                	private JPanel buttonJPanel;
                	private JPanel fieldJPanel;
                	private JPanel fontJPanel;
                	private int currProd = 0;
                	private double total; // variable for total inventory
                
                
                
                	public Inventory()
                	{
                		initComponents();
                	}
                
                	private void initComponents()
                	{
                		prodNameLabel = new JLabel("Product Name:");
                		numberLabel = new JLabel("Item Number:");
                		unitLabel = new JLabel("In Stock:");
                		priceLabel = new JLabel("Each Item Cost:");
                		featureLabel = new JLabel("Type of Item:");
                		valueLabel = new JLabel("Value of Item Inventory:");
                		rstkLabel = new JLabel("Cost to Re-Stock Item:");
                		totalLabel = new JLabel("Total Value of Inventory:");
                
                		firstBtn = new JButton("First");
                		prevBtn = new JButton("Previous");
                		nextBtn = new JButton("Next");
                		lastBtn = new JButton("Last");
                
                		prodNameField = new JTextField();
                		prodNameField.setEditable(false);
                		numberField = new JTextField();
                		numberField.setEditable(false);
                		unitField = new JTextField();
                		unitField.setEditable(false);
                		priceField = new JTextField();
                		priceField.setEditable(false);
                		featureField = new JTextField();
                		featureField.setEditable(false);
                		valueField = new JTextField();
                		valueField.setEditable(false);
                		rstkField = new JTextField();
                		rstkField.setEditable(false);
                		totalField = new JTextField();
                		totalField.setEditable(false);
                
                		prodNameLabel.setSize(200, 20);
                		numberLabel.setSize(200, 20);
                		unitLabel.setSize(200, 20);
                		priceLabel.setSize(200, 20);
                		featureLabel.setSize(200, 20);
                		valueLabel.setSize(200, 20);
                		rstkLabel.setSize(200, 20);
                		totalLabel.setSize(200, 20);
                
                		prodNameField.setSize(100, 20);
                		numberField.setSize(100, 20);
                		unitField.setSize(100, 20);
                		priceField.setSize(100, 20);
                		featureField.setSize(100, 20);
                		valueField.setSize(100, 20);
                		rstkField.setSize(100, 20);
                		totalField.setSize(100, 20);
                
                		buttonJPanel = new JPanel(); // set up panel
                		buttonJPanel.setLayout( new GridLayout(1, 4)); //set layout
                		// add buttons to buttonJPanel
                		buttonJPanel.add(firstBtn);
                		buttonJPanel.add(prevBtn);
                		buttonJPanel.add(nextBtn);
                		buttonJPanel.add(lastBtn);
                
                
                
                    }
                    public static void main( String args[])
                    {
                      product[] myProduct = new product[5];
                      //Company[] myCompany = new Company[5];
                
                        product p1 = new Company("Mad Dash", 20003, 5, 30, "EIDOS");
                        product p2 = new Company("Fuzion Frenzy", 74512, 2, 10, "MicroSoft");
                        product p3 = new Company("Time Splitters 2", 20009, 3, 45, "EIDOS");
                        product p4 = new Company("Night Caster", 74522, 8, 5, "MicroSoft");
                        product p5 = new Company("Lego Star Wars II", 32976, 1, 50, "LucasArts");
                
                        myProduct[0] = p1;
                        myProduct[1] = p2;
                        myProduct[2] = p3;
                        myProduct[3] = p4;
                        myProduct[4] = p5;
                
                        double totalValue = 0.0;
                
                        for (int c=0; c < 5; c++)
                        {
                            totalValue = totalValue + myProduct[c].itemCalculate();
                        }
                
                        Arrays.sort(myProduct); // function used to sort arrays
                
                        for(product p: myProduct)
                        {
                            System.out.println(p);
                            System.out.println();
                        }
                       System.out.println("Total Inventory value is: $"+totalValue);
                
                   } //end main
                
                } //end Inventory

                Code:
                import java.util.*;
                
                public class Company extends product implements Comparable
                {
                    private String developer;
                    //double total;
                
                    /** Creates a new instance of Company */
                    public Company()
                    {
                        super();
                        String developer ="";
                        //total =0.0;
                    }
                    public Company(String productName, int itemNumber, double unitProduct, double priceProduct, String developer)
                    {
                        super(productName, itemNumber, unitProduct, priceProduct);
                        this.developer = developer;
                    }
                
                        public void setDeveloper( String developer)
                         {
                            this.developer = developer;
                         }
                        public String getDeveloper()
                         {
                            return developer;
                         }
                
                        public double itemCalculate()
                        {
                            return (super.itemCalculate()*.05)+super.itemCalculate();
                        }
                
                        public int compareTo (Object o) // use the compareTo method
                        {
                            product p = (product)o;
                            return productName.compareTo(p.getProductName());
                        }
                
                        public String toString()
                        {
                         return super.toString()+ "\nCompany: "+ developer +"\nPrice with restock fee: $"+itemCalculate();
                        }
                }

                Code:
                import java.util.*; // program uses any class available
                
                class product implements Comparable
                {
                   public String productName; // class variable that stores the item name
                   private int itemNumber; // class variable that stores the item number
                   private double unitProduct; // class variable that stores the quantity in stock
                   private double priceProduct; // class variable that stores the item price
                
                    /** Creates a new instance of product */
                    public product() // Constructor for Product class
                     {
                        productName = "";
                        itemNumber = 0;
                        unitProduct = 0.0;
                        priceProduct = 0.0;
                     }
                    public product( String productName, int itemNumber, double unitProduct, double priceProduct) // Constructor for myProduct class
                    {
                        this.productName = productName;
                        this.itemNumber = itemNumber;
                        this.unitProduct = unitProduct;
                        this.priceProduct = priceProduct;
                    }
                
                      public void setProductName(String name)  // Method to set the item name
                       {
                         this.productName = productName;
                       }
                      public String getProductName()  // Method to get the item name
                       {
                         return productName;
                       }
                      public void setItemNumber(int number)  // Method to set the item number
                       {
                         this.itemNumber = itemNumber;
                       }
                      public int getItemNumber()  // Method to get the item name
                       {
                         return itemNumber;
                       }
                       public void setUnitProduct(double unit)  // Method to set the item number
                       {
                         this.unitProduct = unitProduct;
                       }
                      public double getUnitProduct()  // Method to get the item name
                       {
                         return unitProduct;
                       }
                       public void setPriceProduct(double price)  // Method to set the item number
                       {
                         this.priceProduct = priceProduct;
                       }
                      public double getPriceProduct()  // Method to get the item name
                       {
                         return priceProduct;
                       }
                
                // Calculation method
                  public double itemCalculate()
                   {
                        return unitProduct * priceProduct; // multiply for total for each item
                
                   } // end calculation
                  public int compareTo (Object o) // use the compareTo method
                    {
                      product p = (product)o;
                         return productName.compareTo(p.getProductName());
                    }
                
                  public String toString() // displays products
                  {
                      return "Title: "+productName+
                              "\nBarcode: "+itemNumber+
                              "\nNumber of Xbox games: "+(int)unitProduct+
                              "\nPrice: $"+priceProduct+
                              "\nTotal: $"+itemCalculate();
                   } // end toString
                
                
                }//end class Supplies

                Comment

                • madhoriya22
                  Contributor
                  • Jul 2007
                  • 251

                  #9
                  Originally posted by nexcompac
                  Ok, so I removed the line to work backwards to move forward. Now, it complies but the GUI does not show up. When I run the program it goes to the comand prompt.

                  Hi,
                  Declare ur list like this .. to remove the ambiguity
                  Code:
                   
                  private java.awt.List nwProduct;
                  private void initComponents()
                  	{
                  nwProduct = new java.awt.List();
                  GUI is not creating bcoz u r not creating any object of ur inventory class in main method.
                  thanks and regards,
                  madhoriya22

                  Comment

                  Working...