Forums Register Login

Image is not getting loaded in applet

+Pie Number of slices to send: Send
Hi,

I have downloaded the folowing code from javaranch site.
Able to compile the java prog, im getting msg applet started at the status bar but image is not getting loaded,I tried printing the msg in the where im calling g.drawImage () method.String is displayed on the applet but image is not coming.can any one tel what could be the reason .

thnx & regards
madhavi


import java.applet.* ;
import java.awt.* ;

public class LoadAGifMsg extends Applet
{
private Image theHorse ;
private Image theMoose ;
private boolean showWaitMsg = true ; // will be set to false after image downloads

public void init()
{
// anything in here will run BEFORE the paint() method is called,
// even if you call repaint() now inside init
} // close init

public void loadGraphics()
{
// now load the graphics - this is like your "real" init
theHorse = getImage( getCodeBase() , "M1.JPEG" );
theMoose = getImage( getCodeBase() , "M2.JPEG" );
MediaTracker mt = new MediaTracker( this );
mt.addImage( theHorse , 0 );
mt.addImage( theMoose , 1 );

try
{
mt.waitForAll(); // block here until images are downloaded
}
catch ( InterruptedException e )
{
}

showWaitMsg = false ; // it is safe for paint to draw the image now
repaint();
} // close loadGraphics

public void paint( Graphics g )
{
// test a boolean to if the "loading" message should be displayed
if ( showWaitMsg )
{
g.drawString( "Please wait... loading..." , 20 , 20 );
loadGraphics(); // call the method that actually loads the graphics
}
else
{
g.drawImage( theHorse , 25 , 25 , this );
g.drawImage( theMoose , 25 , 130 , this );
}
} // close paint
}
+Pie Number of slices to send: Send
Are the files M1.JPEG and M2.JPEG in the same directory as the applet's HTML file?
+Pie Number of slices to send: Send
Offcourse yes , they r in the same directory......
+Pie Number of slices to send: Send
Hmm. I misspoke, actually -- you're using getCodeBase() for the URLs, so the images have to be in the same place as the .class file. I'll assume that the .class file is in the same directory, too. If the .class is in a JAR, then the images will have to be in there, too.

Maybe you've just got the applet's area too small in the HTML file? The coordinates given to drawString() are the lower-left corner of the String, while those given to drawImage are the top-left corner of the image, so the top of the upper image will be five pixels below the bottom of the String.
+Pie Number of slices to send: Send
Your assumption is corect.Class file is also in the same directory.No class is not in jar file.Width and height are 900/900.still not able to get.........
+Pie Number of slices to send: Send
I tried printing the url of the image
its printing sun.awt.windows.WImage@10da5ed
i dont know from where it is picking above url
my .java,.class,.htmland .jpeg files are in c drive.

guys help me out ..........
+Pie Number of slices to send: Send
 

Originally posted by madhavi prasad:
Hi,

theHorse = getImage( getCodeBase() , "M1.JPEG" );
theMoose = getImage( getCodeBase() , "M2.JPEG" );

}



Hi,
+Pie Number of slices to send: Send
 

Originally posted by alexandre soares:


Hi,



Hi, the illustration doesn't open, therefore the jvm this seeking in the root (c , then put the complete road
example:

theHorse = getImage( getCodeBase() , "c:\\folder\\M1.JPEG" );
theMoose = getImage( getCodeBase() , "c:\\folder\\M2.JPEG" );

by
+Pie Number of slices to send: Send
Hi,

When i have given the path
eg: madhavi=getImage( getCodeBase(), "C:\\M1.JPEG" );
it is throwing nullpointer exception
at the below line
g.drawImage( madhavi , 25 , 25 , this )
+Pie Number of slices to send: Send
Yes. You can't use absolute file paths in an applet, anyway -- that's a bad suggestion.

This is a tough one. Have you viewed the image files in some other program to make sure they're OK?
+Pie Number of slices to send: Send
I dont hav any other program to chk
but i hav tried giving gif images of small size
even no out put how do i solve this
There is no "i" in denial. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1398 times.
Similar Threads
Image+Button+applet
applet LoadAGif can't start: error????
Display image using getCodeBase() method
applet LoadAGif can't start: error????
JPEG file not getting loaded in the aspplet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:07:09.