• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Images in Java

 
Trey German
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Trey German
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the gif file in the correct directory?
 
Trey German
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I believe it is in the correct directory.
 
Trey German
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it working thanx
 
Trey German
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
 
Jason Moon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im still having a little prob with the making an image... Where is the html directory?
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Jason Moon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So.. is it in the Jbuilder directory?? Windows??? scr?? i can't find it
 
Jason Moon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic