Results 1 to 14 of 14
  1. #1
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default I need help with putting a logo on my code

    Here is the code for my logo but i have two error and i am not sure where it would go can someone please help me. The top code is the logo code and the buttom is my inventory code.. and i am getting 2 errors with this.

    C:\Java Test>javac InventoryPart5.java
    InventoryPart5.java:137: error: cannot find symbol
    Label = new JLabel(logo);
    ^
    symbol: variable Label
    location: class InventoryPart5
    InventoryPart5.java:138: error: cannot find symbol
    Label.setToolTipText("Camera Shop");
    ^
    symbol: variable Label
    location: class InventoryPart5
    2 errors





    Java Code:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    public class Logo extends JPanel {
    	public Logo() {
    		super();
    		setPreferredSize(new Dimension(200,200));
    	}
    	public void paint(Graphics g) {
    		g.setColor(Color.red);
    		g.fillRoundRect(60,60,110,90,5,5);
    		g.setColor(Color.blue);
    		g.drawString("DVD Store", 70, 105);
    	}
    }


    Java Code:
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.DecimalFormat;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    
    
    public class InventoryPart5 extends JFrame {
    	private static DecimalFormat currency = new DecimalFormat("$#,##0.00");
    
    
    	private JTextField itemNumberTF;
    	private JTextField productNameTF;
    	private JTextField unitsInStockTF;
    	private JTextField priceTF;
    	private JTextField supplierNameTF;
    	private JTextField restockFeeTF;
    	private JTextField valueOfInventoryTF;
    
    	
    	private JTextField totalValueOfInventoryTF;
    
    	private JButton FirstBT;
    	private JButton BackBT;
    	private JButton nextBT;
        private JButton lastBT;
    	
    	private Supplier[] products;
    
    	
    	private int current = 0;
    
    	
    	public static void main(String[] args) {
    	
    		new InventoryPart5();
    	}
    	public InventoryPart5() {
    		super("Inventory Part 5");
    		setSize(500, 300);
    		setLocationRelativeTo(null);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    
    		
    		products = new Supplier[5];
    
    		
    		products[0] = new Supplier(500, "STYLUS", 10, 800, "Olympus");
    		products[1] = new Supplier(200, "COOLPIX", 20, 650, "Nikon");
    		products[2] = new Supplier(300, "Powershot", 15, 890, "Canon");
    		products[3] = new Supplier(350, "Cyber-shot", 10, 1200, "Sony");
    		products[4] = new Supplier(400, "Easyshare", 80, 1500, "Kodak");
    
    		
    		sortArray();
    
    		
    		createComponents();
    
    		
    		setVisible(true);
    
    		
    		updateFields();
    	}
    
    	private void createComponents() {
    		JPanel p = new JPanel();
    		p.setLayout(new BorderLayout());
    		p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    
    		p.add(createFieldsPanel(), BorderLayout.CENTER);
    		p.add(createButtonsPanel(), BorderLayout.SOUTH);
    
    		setContentPane(p);
    	}
    	
    
    	private JPanel createButtonsPanel() {
    		JPanel p = new JPanel();
    		p.setLayout(new FlowLayout(FlowLayout.RIGHT));
           
    	    FirstBT = new JButton("First");
    		FirstBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				current = 0;
    				updateFields();
    			}
    		});
    		p.add(FirstBT);
    		
    	    BackBT = new JButton("Back");
    		BackBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (current > 0) {
    					current--;
    					updateFields();
    				}
    			}
    		});
    		p.add(BackBT);
    
    		nextBT = new JButton("Next");
    		nextBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (current < products.length - 1) 
    					current++;
    					updateFields();
    				
    			}
    		});
    		p.add(nextBT);
    		
            lastBT = new JButton("Last");
    		lastBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				 current = products.length-1;
    				updateFields();
    				
    			}
    		});
    		p.add(lastBT);
    		
    		Icon logo = new ImageIcon("C:/logo.jpg"); 
    	Label = new JLabel(logo); 
    	Label.setToolTipText("Camera Shop"); 
    		return p;
    	}
    
    	
    	protected void updateFields() {
    		Supplier s = products[current];
    
    		itemNumberTF.setText(String.valueOf(s.getItemNumber()));
    		productNameTF.setText(s.getProductName());
    		unitsInStockTF.setText(String.valueOf(s.getUnitsInStock()));
    		priceTF.setText(currency.format(s.getPrice()));
    		supplierNameTF.setText(s.getSupplierName());
    		restockFeeTF.setText(currency.format(s.calculateRestockFee()));
    		valueOfInventoryTF.setText(currency.format(s.calculateInventory()));
    
    		totalValueOfInventoryTF.setText(currency.format(calculateInventory()));
    	}
    
    	private JPanel createFieldsPanel() {
    		JPanel p = new JPanel();
    		p.setLayout(new GridLayout(0, 2, 5, 5));
    
    		p.add(new JLabel("Item Number"));
    		itemNumberTF = new JTextField();
    		p.add(itemNumberTF);
    
    		p.add(new JLabel("Product Name"));
    		productNameTF = new JTextField();
    		p.add(productNameTF);
    
    		p.add(new JLabel("Units In Stock"));
    		unitsInStockTF = new JTextField();
    		p.add(unitsInStockTF);
    
    		p.add(new JLabel("Unit Price"));
    		priceTF = new JTextField();
    		p.add(priceTF);
    
    		p.add(new JLabel("Supplier Name"));
    		supplierNameTF = new JTextField();
    		p.add(supplierNameTF);
    
    		p.add(new JLabel("Restock Fee"));
    		restockFeeTF = new JTextField();
    		p.add(restockFeeTF);
    
    		p.add(new JLabel("Value Of Inventory"));
    		valueOfInventoryTF = new JTextField();
    		p.add(valueOfInventoryTF);
    
    		p.add(new JLabel(""));
    		p.add(new JLabel(""));
    
    		p.add(new JLabel("Value Of The Entire Inventory"));
    		totalValueOfInventoryTF = new JTextField();
    		p.add(totalValueOfInventoryTF);
    
    		return p;
    	}
    
    	
    	public double calculateInventory() {
    		double value = 0;
    		for (int i = 0; i < products.length; i++) {
    			value += products[i].calculateInventory();
    		}
    		return value;
    	}
    
    	
    	public void sortArray() {
    		int n = products.length; 
    		boolean swapped;
    		do {
    			swapped = false;
    			for (int i = 0; i < n - 1; i++) {
    				String name1 = products[i].getProductName();
    				String name2 = products[i + 1].getProductName();
    				if (name1.compareToIgnoreCase(name2) > 0) {
    					
    					Supplier temp = products[i];
    					products[i] = products[i + 1];
    					products[i + 1] = temp;
    					swapped = true;
    				}
    			}
    			n = n - 1;
    		} while (swapped);
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help with putting a logo on my code

    Quote Originally Posted by MikeJ39 View Post
    and i am getting 2 errors with this.

    C:\Java Test>javac InventoryPart5.java
    InventoryPart5.java:137: error: cannot find symbol
    Label = new JLabel(logo);
    ^
    symbol: variable Label
    location: class InventoryPart5
    InventoryPart5.java:138: error: cannot find symbol
    Label.setToolTipText("Camera Shop");
    ^
    symbol: variable Label
    location: class InventoryPart5
    2 errors
    Java is telling you: you're using a variable named "Label", but where do you declare this variable?

    Where do you declare it?

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: I need help with putting a logo on my code

    error: cannot find symbol
    You have not declared Label anywhere.

  4. #4
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default Re: I need help with putting a logo on my code

    ok how do i do that

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help with putting a logo on my code

    Quote Originally Posted by MikeJ39 View Post
    ok how do i do that
    Just like you declare any other variable: type variable name;

    Also note that it should be label not Label.

    i.e.,
    Java Code:
    JLabel label;  // declares label
    Or you can declare and initialize on the same line:
    Java Code:
    JLabel label = new JLabel("...");  // declares and initializes label

  6. #6
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default Re: I need help with putting a logo on my code

    ok in what area would i put that in or line

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help with putting a logo on my code

    Quote Originally Posted by MikeJ39 View Post
    ok in what area would i put that in or line
    Before you use the variable. You never seem to add the variable to anything, and the code shows no problem in declaring the other variables. I have to ask, is this originally your code?

  8. #8
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default Re: I need help with putting a logo on my code

    yes this is my original code

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help with putting a logo on my code

    Heck, this is the same error that you had in this post yesterday in code guru: CodeGuru: Error In code need Help please ... and they already told you what the error message meant and its solution. The solution hasn't changed in one day.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help with putting a logo on my code

    Quote Originally Posted by MikeJ39 View Post
    yes this is my original code
    But a search on Google shows that much of your code has been borrowed (e.g., stackoverflow: modify-the-inventory-program-to-use-a-gui), and it has to be -- you use anonymous inner classes in this code -- surely you weren't taught that in class, and I fear that you don't understand what they are or why you're using them.

    You really don't want to use borrowed code as you won't understand the code you're using and this will hamper your attempt to learn to program.
    Last edited by Fubarable; 10-22-2011 at 01:39 AM.

  11. #11
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default Re: I need help with putting a logo on my code

    no this is diffrent error i got that one fix

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help with putting a logo on my code

    Quote Originally Posted by MikeJ39 View Post
    no this is diffrent error i got that one fix
    How is this error different?
    • Both have the same error message: " error: cannot find symbol"
    • Both are due to the same issues: using a variable but not declaring it first.
    • Both are solved by the same solution: declare the variable first.

  13. #13
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default Re: I need help with putting a logo on my code

    well that didnt help me like i said i have a code but i just dont know where to put in i need to put a logo in my code somewhere.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help with putting a logo on my code

    Quote Originally Posted by MikeJ39 View Post
    well that didnt help me like i said i have a code but i just dont know where to put in i need to put a logo in my code somewhere.
    Again, you should create your own program for this and not borrow outside code. Then you'll be able to easily place logos and whatnots wherever you like.

Similar Threads

  1. Legal to use the Java Logo?
    By developjava in forum Forum Lobby
    Replies: 2
    Last Post: 06-02-2012, 09:16 PM
  2. setting application logo to tab
    By sameerk in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 10-29-2010, 12:36 PM
  3. Adding Logo to my project
    By ibrahimyoussof in forum New To Java
    Replies: 0
    Last Post: 04-14-2010, 11:56 AM
  4. Adding Logo to Video Uploading by Java swing
    By arindam in forum New To Java
    Replies: 0
    Last Post: 11-12-2008, 04:14 PM
  5. Putting code together.
    By newbee in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 04:53 AM

Posting Permissions

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