Results 1 to 10 of 10
  1. #1
    elecleoalune is offline Member
    Join Date
    Mar 2011
    Posts
    35
    Rep Power
    0

    Default how to import downloaded .gif files into the software.

    Hi guys,
    for this project I am to nest different images that I downloaded into my program so that when I run it it will show the pictures. I downloaded couple pictures but the program seems to not detect the images (I don't get the images I want where I want them, instead get blanks). Where should I be placing the images so that I can use them in Frame?

    MY PROJECT:

    // Demonstrates the use of image icons in labels.

    import java.awt.*;
    import javax.swing.*;

    public class listing0309 {
    // Creates and displays the primary application frame.
    public static void main (String[] args)
    {
    JFrame frame = new JFrame ("Label Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    ImageIcon icon = new ImageIcon ("fat big devil.gif");

    JLabel label1, label2, label3;

    label1 = new JLabel ("Devel Left", icon, SwingConstants.CENTER);

    label2 = new JLabel ("Devil Right", icon, SwingConstants.CENTER);
    label2.setHorizontalTextPosition (SwingConstants.LEFT);
    label2.setVerticalTextPosition(SwingConstants.BOTT OM);

    label3 = new JLabel ("Devil Above", icon, SwingConstants.CENTER);
    label3.setHorizontalTextPosition(SwingConstants.CE NTER);
    label3.setVerticalTextPosition(SwingConstants.BOTT OM);

    JPanel panel = new JPanel();
    panel.setBackground(Color.cyan);
    panel.setPreferredSize(new Dimension (200,250));
    panel.add (label1);
    panel.add (label2);
    panel.add(label3);

    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);

    }
    }


    WHAT I SHOULD BE SEEING:

    I should be seeing 3 fat big devils in the frame. The most top image should be at the left (with the label "Devil Left" on the right of the image), the middle one should be at the mid right (with the label "Devil Right" on the left of the image), and the last picture should be at bottom middle (with the label "Devil Above" right below the image).

    WHAT I AM GETTING:

    I am getting only the labels in cyan frame with no images...

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Are you sure the source of the .gifs is correct?

  3. #3
    elecleoalune is offline Member
    Join Date
    Mar 2011
    Posts
    35
    Rep Power
    0

    Default

    well i am not sure if it's correct or not...
    How do I check if it is in Linux?
    Since I am using Linux, I feel completely turned around.

  4. #4
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Yeah I'm not a linux user so I have no idea if the file paths are different. I would assume they are similar, but possibly different enough to cause an issue.

    I found this article on google that may help you.
    Java Swing: how to add an image to a JPanel ? - Stack Overflow

  5. #5
    elecleoalune is offline Member
    Join Date
    Mar 2011
    Posts
    35
    Rep Power
    0

    Default

    no luck, thanks though.
    since I don't understand most of the commands, even if they might be explaining it, I am not understanding it...
    I tried to find the path for the picture, but still no luck...
    I guess I'll just have to come back to this set of problem for now.
    BUT if anyone would still like to give me tips, I would love to listen and try them out.

  6. #6
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Hopefully someone with more experience with JPanel and importing gifs will log in and help you out.

  7. #7
    elecleoalune is offline Member
    Join Date
    Mar 2011
    Posts
    35
    Rep Power
    0

    Default

    NO WAIT! IT'S ALIVE!!! MUHAHAHAHA
    lol I tried putting the .gif files into the same folder as the src file folder where my project is saved under and it started working just fine.
    I am not sure if it's that or me just messing around with the 'search' tool...
    but it worked~!

  8. #8
    elecleoalune is offline Member
    Join Date
    Mar 2011
    Posts
    35
    Rep Power
    0

    Default

    thanks for trying DARK, sometimes that means more than anything~!
    it kept me encouraged~! :) cheers to Java Forums and its little helper

  9. #9
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Aha, sorry I assumed you already put it in your src folder.

  10. #10
    elecleoalune is offline Member
    Join Date
    Mar 2011
    Posts
    35
    Rep Power
    0

    Default

    nop, that's what i get for being a complete novice at this.
    However, I learned another lesson today right?
    One baby steps at a time I say~

Similar Threads

  1. Import my own class files into eclipse
    By teaicky in forum New To Java
    Replies: 3
    Last Post: 02-07-2011, 10:45 PM
  2. how to import packages files to my applet in netbean
    By funkygarzon in forum Java Applets
    Replies: 4
    Last Post: 08-16-2010, 08:02 PM
  3. import from dsv files and export to csv files
    By 10x2 in forum New To Java
    Replies: 12
    Last Post: 04-30-2010, 12:56 PM
  4. Import files from NetBeans
    By Juuno in forum Eclipse
    Replies: 2
    Last Post: 04-08-2009, 06:20 AM
  5. unable to import jar files (crystal report 11)
    By kishore101 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-25-2009, 08:51 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
  •