Results 1 to 10 of 10
- 04-12-2011, 11:29 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
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...
- 04-12-2011, 12:47 PM #2
Are you sure the source of the .gifs is correct?
- 04-12-2011, 01:10 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
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.
- 04-12-2011, 01:21 PM #4
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
- 04-12-2011, 02:03 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
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.
- 04-12-2011, 02:06 PM #6
Hopefully someone with more experience with JPanel and importing gifs will log in and help you out.
- 04-12-2011, 02:07 PM #7
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
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~!
- 04-12-2011, 02:08 PM #8
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
thanks for trying DARK, sometimes that means more than anything~!
it kept me encouraged~! :) cheers to Java Forums and its little helper
- 04-12-2011, 02:13 PM #9
Aha, sorry I assumed you already put it in your src folder.
- 04-12-2011, 02:27 PM #10
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
Import my own class files into eclipse
By teaicky in forum New To JavaReplies: 3Last Post: 02-07-2011, 09:45 PM -
how to import packages files to my applet in netbean
By funkygarzon in forum Java AppletsReplies: 4Last Post: 08-16-2010, 07:02 PM -
import from dsv files and export to csv files
By 10x2 in forum New To JavaReplies: 12Last Post: 04-30-2010, 11:56 AM -
Import files from NetBeans
By Juuno in forum EclipseReplies: 2Last Post: 04-08-2009, 05:20 AM -
unable to import jar files (crystal report 11)
By kishore101 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-25-2009, 07:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks