aspose file tools*
The moose likes Beginning Java and the fly likes Images in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Images in Java" Watch "Images in Java" New topic
Author

Images in Java

Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
I'am having trouble putting images in my java applets can someone please send me some source code that works for sure. All the code that I've found doesn't seem to work. THANX
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Jungle.gif I found laying around in the MicroSoft stuff on my PC and moved it to my DocumentBase directory (the directory that the HTML holding the Applet sits in).


"JavaRanch, where the deer and the Certified play" - David O'Meara
Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
Thanx for the code the applet looks like its working but now it just gives me a grey square when i open the applet. I have a feeling its just the computer i'm using but it is doing it on all the computers i've tried do you have any suggestions?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Is the gif file in the correct directory?
Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
Yes. I believe it is in the correct directory.
Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
i got it working thanx
Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
Also will the same code work in a java program, and if it doesn't sould you give me some that will
THANX
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well you can't use DocumentBase of course. You will need to use something like:
Image myImage = Toolkit.getDefaultToolkit().createImage(�myPic.jpg�);
or
Image myImage = Toolkit.getDefaultToolkit().createImage(new URL(�http://www.javaranch.com/Cindy/Cindy2.jpg�));
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jason Moon
Greenhorn

Joined: Dec 11, 2002
Posts: 3
im still having a little prob with the making an image... Where is the html directory?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
sporkboy ???
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Jason Moon
Greenhorn

Joined: Dec 11, 2002
Posts: 3
So.. is it in the Jbuilder directory?? Windows??? scr?? i can't find it
Jason Moon
Greenhorn

Joined: Dec 11, 2002
Posts: 3
ok ok ok..... after hours and hours of tedious work.. I imported java.net.*; and used
myImage = getImage(new URL("http://www.javaranch.com/Cindy/Cindy2.jpg"));
that works but what if I want to get a Image off my own Computer??
Can somone help me??? i've been seriously trying for hours..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Images in Java
 
Similar Threads
Combine multiple images with mosaic JAI
table using lwuit in j2me
problem with server relative paths for images
response code: 400 from google images
Regex, is forward slash the problem ?