Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Adding logo into my program

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Adding logo into my program

    So I am trying to add a logo to my existing program. However nothing shows up when I run it. I am getting no errors and everything else seems to be fine. Can some one tell me what I am missing?

    This is just the logo part if you need the whole code it will be separate (just trying to make things easier.
    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.black);
    			g.drawString("DEAD BUG", 70, 105);
    		}
    	}
    Here is the entire program.
     import java.util.Scanner;
    import java.util.Arrays;
    import java.lang.String;
    import static java.lang.System.out;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    // all imports for program
     
    public class InventoryProgram
    {
     
    	// main method begins program execution
    	public static void main(String args[] )
    	{
     
     
    		// display a welcome message to the InventoryProgram to user
    		System.out.println( "Welcome to Inventory Program!" );
     
    		//Supplies[] supplies = new Supplies[100]; // an array of 100 supplies
    		/***
    		 * Use Child class array
    		 */
    		Manufacturer[] supplies = new Manufacturer[5]; // an array of 100 supplies
     
    		/*
    		- USE AN ARRAY OF CHILD OBJECTS AS SHOWN BELOW
    		Supplies Maverick = new Supplies( 001, "Maverick", 60, 2.75 );          
    		Supplies Termidor = new Supplies( 002, "Termidor", 75, 1.25 );
    		Supplies Bithor = new Supplies( 003, "Bithor", 30, 4.75 );
    		Supplies Demon = new Supplies( 004, "Demon", 15, 5.25 );
    		Supplies DeltaDust = new Supplies( 005, "Delta Dust", 45, 3.50 );
    		*/
     
    		//Adding Child objects to the array
    		supplies[0] = new Manufacturer( 001, "Maverick", 60, 2.75, "Univar inc." );          
    		supplies[1] = new Manufacturer( 002, "Termidor", 75, 1.25, "Dupont" );
    		supplies[2] = new Manufacturer( 003, "Bithor", 30, 4.75, "Bayer" );
    		supplies[3] = new Manufacturer( 004, "Demon", 15, 5.25, "Dow Chemicals" );
    		supplies[4] = new Manufacturer( 005, "Delta Dust", 45, 3.50, "Ipsothor" );
     
    		// display the inventories one at a time
    		/*
    		Maverick.showInventory();
    		Termidor.showInventory();
    		Bithor.showInventory();
    		Demon.showInventory();
    		DeltaDust.showInventory();
    		*/
     
    		//OUTPUT ITEMS FROM ARRAY		
    		for(int i = 0; i < supplies.length; ++i){
    			supplies[i].showInventory();
    		}
     
    		NewJFrame gui = new NewJFrame(); //Call GUI
    		gui.addData(supplies);  //Passing Data to the GUI
     
    	} // end method main
     
    }     // end class InventoryProgram     
     
    // Office Supplies
    class Supplies
    {
    	private int SuppliesNumber;
    	private String SuppliesName = new String();
    	private int SuppliesUnits;
    	private double SuppliesPrice;
     
    	// set supplies number
    	public void setSuppliesNumber( int number )
    	{
    		this.SuppliesNumber = number;
    	} // end method set supplies number
     
    	// return supplies number
    	public float getSuppliesNumber()
    	{
    		return SuppliesNumber;
    	} // end method get supplies number
     
    	// set supplies name
    	public void setSuppliesName( String name )
    	{
    		this.SuppliesName = name;
    	} // end method set supplies name
     
    	// return supplies name
    	public String getSuppliesName()
    	{
    		return SuppliesName;
    	} // end method get supplies name
     
    	// set supplies in stock
    	public void setSuppliesUnits( int units )
    	{
    		this.SuppliesUnits = units;
    	} // end method set supplies units
     
    	// return supplies units
    	public int getSuppliesUnits()
    	{
    		return SuppliesUnits;
    	} // end method get supplies units
     
    	// set supplies price
    	public void setSuppliesPrice( double price )
    	{
    		this.SuppliesPrice = price;
    	} // end method set supplies price
     
    	// return supplies price
    	public double getSuppliesPrice()
    	{ 
    		return SuppliesPrice;
    	} // end method get supplies price
     
    	// calculate supplies inventory value
    	public double getValue()
    	{
    		return SuppliesUnits * SuppliesPrice;
    	} // end method supplies inventory value 
     
    	// four-argument constructor
    	Supplies( int number, String name, int units, double price )
    	{ 
    		SuppliesNumber = number;
    		SuppliesName = name;
    		SuppliesUnits = units;
    		SuppliesPrice = price;
    	} // end four-argument constructor
     
    	// display inventory
    	public void showInventory()
    	{
    		System.out.println(); // outputs blank line
     
    		System.out.println( "Product Number:  "+SuppliesNumber );
    		System.out.println( "Product Name:  "+SuppliesName );
    		System.out.println( "Number of Units:  "+SuppliesUnits );
    		System.out.printf( "Unit Price:  $%.2f", SuppliesPrice );
     
    		// value() method and display the value
    		System.out.printf( "\nInventory value of "+SuppliesName+ " is = $%.2f\n",
    				getValue() );     
     
    	} // end display inventory
     
    	//return String representation of suppliesManufacturer
    	public String toString()
    	{
    		String formatString =  String.format("Product Number:  %d \n", SuppliesNumber);
    		formatString += String.format("Product Name:  %s \n", SuppliesName);
    		formatString += String.format("Number of Units:  %d \n", SuppliesUnits);
    		formatString += String.format("Units Price:  $%.2f \n", SuppliesPrice);
     
    		return( formatString);
     
    	} // end toString()	
     
     
    } // end class supplies
     
    class Manufacturer extends Supplies
    {
    	// holds the supplies manufacturer
    	private String suppliesManufacturer;
     
    	// five-argument constructor
    	Manufacturer( int number, String name, int units, double price, String manufacturer )
    	{
    		super( number, name, units, price );
    		suppliesManufacturer = manufacturer;
    	}   // end five-argument constructor
     
    	// set supplies manufacturer
    	public void setManufacturer( String manufacturer )
    	{
    		this.suppliesManufacturer = manufacturer;
    	} // end method set supplies manufacturer
     
    	// return supplies manufacturer
    	public String getManufacturer()
    	{
    		return suppliesManufacturer;
    	}   // end method get supplies manufacturer
     
    	// add 5% restocking fee
    	public double getValue()
    	{
    		return super.getValue() * 1.05;
    	} // end method return supplies manufacturer
     
    	// calculate restocking fee
    	public double getRestockingFee()
    	{
    		return super.getValue() * .05;
    	} //end method calculate restocking fee
     
    	//return String representation of suppliesManufacturer
    	public String toString()
    	{
    		String formatString = super.toString();
    		formatString += "Manufacturer:  %s \n";
    		formatString += "Restocking Fee:  $%.2f \n";
    		formatString += "Inventory Value:  $%.2f \n";
    		formatString = String.format( formatString, suppliesManufacturer,
    				getRestockingFee(), getValue());
    		return( formatString);
     
    	} // end toString()
     
    	// display inventory
    	public void showInventory()
    	{
    		super.showInventory();
    		System.out.println( toString() );
     
    	} // end method display inventory
     
    }// end class manufacturer
     
    // Start of GUI class 
    class NewJFrame extends javax.swing.JFrame {
     
        private JTextArea area; //Define Needed Objects and Variables
        private JButton next;
        private static int count = 0;
        //Keep track of current item which helps with button logic
        private JButton back;
        private JButton first;
        private JButton last;
     
        private Manufacturer[] info; //Declare Array
     
        //Constructor that runs when object is created
        public NewJFrame()
        {
     
            setTitle("GUI"); //Set GUI Title
     
            JPanel panel = new JPanel(); //Use JPanel to hold ifo
            area = new JTextArea(12, 20); //Set JTextArea Size
            panel.add(area); //Add to JPanel
     
            next = new JButton("Next"); //create JButton
            back = new JButton("Back"); 
            first = new JButton("First"); 
            last = new JButton ("Last"); 
            // creates all buttons.
     
            panel.add(next); //Add Button to JPanel
            add(panel); //Add JPanel to JFrame
    		panel.add(back);
    		add(panel);
    		panel.add(first);
    		add(panel);
    		panel.add(last);
    		add(panel);
    		//adds the JPanels to JFrame for buttons.
     
            ButtonHandler handler = new ButtonHandler();
            //Create Button Handler Object
            next.addActionListener(handler);
            back.addActionListener(handler);
            first.addActionListener(handler); // THESE TWO ARE NOT WORKING!!!!
            last.addActionListener(handler);  //SEE ABOVE NOTE
            //Add Action Listener for JButton to Handler
     
            setSize(375, 275); // Set JFrame Size
            setDefaultCloseOperation(EXIT_ON_CLOSE); // Default Operation on Close
            setLocationRelativeTo(null); //Center On Desktop
            setVisible(true); // Allow JFrame to be seen                      
     
       	 } //End Constructor
     
     
     
    	//Nested Class Handler for Button Clicks
        private class ButtonHandler implements ActionListener
        {
            public void actionPerformed(ActionEvent event) //Check Action
            {
                String text = (String)event.getActionCommand();
                    //Get Text From Button
     
                if (event.getSource() == next)
                //Check Button Source
                {
                    //Check count to determine if increment to next item is desired
                    ++count;
                    if (count == info.length) // "Next Item" until last
                    {
                        count = 0;
                    } //end if
                } //end if / else
                if (event.getSource() == back)
                {
    	            --count;
    	            if (count == info.length)
                {
                	count = 0;
                }
            }
                if (event.getSource() == first)
                {
    	            count=0;
                }
     
                if (event.getSource() == last)
                {
    	            count=4;
                }
                updateView(); //Update View to next item
     
            } //End Method
        } //end nested class 
     
        public void updateView() //Update info to JTextArea of GUI
        {
            //Set data for viewing in the JTextArea area
            area.setText("Item: \n\n");
            area.append(info[count].toString());
            //Call toString information
        }
     
        //Reassign Array Created in main method to info Array
        public void addData(Manufacturer[] manuf)
        {
            info = manuf; //set info array to passed mi array
            count = 0; //ensure count is on 1st item of array
            updateView(); //Show 1st Item by updating view
        }
     
    }
     
     
     
    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.black);
    			g.drawString("DEAD BUG", 70, 105);
    		}
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Adding logo into my program

    Where are you expecting the logo to be shown?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Adding logo into my program

    To be honest the instructions for the assignment do not say where it needs to be shown. all I know is that I must have a logo added to the program and it must be seen when the program runs. Other than that it was "keep it as simple as possible". So anywhere is good for me.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Adding logo into my program

    I didn't verify which container you are using as the application's main window, but if it's a JFrame, you can set the icon image using setIconImage().

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Adding logo into my program

    I don not understand what you are telling me. Yes I used JFrame and JLabel. I just want something simple to basically Display a Text based Logo (i.e. "DEAD BUG"). If I use setIconImage(), will it allow for that , and how would I add that to my program. Your suggestion has not been covered in my class so I am not aware of how to use it.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,324
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Adding logo into my program

    So anywhere is good for me
    Then it's your decision where you want to show it.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Adding logo into my program

    I misunderstood. Usually associating a 'logo' with a program means to feature a graphic or icon somewhere in the program's graphical interface. One way to accomplish that, probably the simplest, is the way I suggested. We are not aware of your limitations unless you tell us, so we're likely to suggest what we know, not what you're allowed to know and/or use.

    Inspecting at your code more closely, I see you're making other basic mistakes that should be corrected in order to display a JLabel with the text, "DEAD BUG".

    1. Do not override the paint() method as you do in class Logo. Instead, override the paintComponent() method.

    2. The default layout for a JFrame is BorderLayout, and components added to a BorderLayout are added to the center of the layout by default.

    3. Only one component at a time can occupy a specific layout area, so the last item added is shown while any others previously added become irrelevant. Your code that modifies a component, adds it, modifies it, adds it, etc., is unnecessary.

    You should be able to complete your interface as desired by referring to the documentation for BorderLayout and using it properly.

  8. #8
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Adding logo into my program

    Ok I see what you are saying now. I don't mean to sound like you guys should know what I need. Just some times You guys give suggestions that are way beyond my skill level, and I know for ya'll that is a basic and simple answer to my question. I hate how segmented this class is as I was unaware of the way you suggested until I looked further into my text and see when we talk about drawing and making images. I some times get so lost I am just fusrtated and want to quit, But I don't.

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Adding logo into my program

    Understand. To help us suggest solutions that are within the bounds of what you can use, try to describe what you're trying to do as specifically as possible including any guidance you've been given or limitations that you're aware of. I know it's hard when you don't know what you don't know, but keep in mind that we don't know what you don't know either.

Similar Threads

  1. What is the logo of Java?
    By vinothcse123 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 5th, 2013, 09:13 AM
  2. Need help adding Displays to a program
    By Lacie1013 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2013, 12:50 PM
  3. [SOLVED] Logo quiz
    By big daan1234 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 15th, 2012, 10:57 AM
  4. This java program is adding up in a negative way....
    By seaofFire in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 23rd, 2012, 05:58 PM
  5. Adding sound to program.
    By Archibold9 in forum What's Wrong With My Code?
    Replies: 32
    Last Post: December 21st, 2011, 02:28 PM