My programming? JRE 1.4 bug? Images not displayed properly!
I made this simple card game which you can checkout at http://www.koutbo6.com I used AWT components and used Panels for drawing the cards and the main game panel has a null Layout. It runs perfectly on all java enabled browsers ... except for IE on windows XP.
I came across a problem where the card images are not displayed at all. some images that are drawn disrectly on the backround are partially drawn or not drawn correctly. The IExplorere had microsft virtual machine donloaded for windows XP. I managed to correct the problem by disabling JIT compiling from IE advanced setting.
Then I installed XP on another PC and was surprized that Microsoft stopped distributing the Java Virtual Machine for XP, so I opted for sun java plugin V1.4 and the same problems occur. There is no way to turn off JIT compiling and i read in oone of the bug postings that the option has been taken off in versio 1.4.
when the problem occurs I noticed that g.drawString works perfectly and all the AWT components are displayed even in the main panel with the null layout. the problem occurs with displaying the images. It could be with the way im doing things.
this is how I draw my images using the paint method:
publicvoid paint(Graphics g){
super.paint(g);
if(cardImage !=null){
g.drawImage(cardImage,0,0,this);
}
}
this is how I draw cards images on card panels, if i wana clear the image I would set cardImage to null and repaint. This is how i draw all the images in the client.
Is there a problem with my way of doing things? or is there a problem with the java plug in? I'v yet to try installing older java plug-ins on this PC, I will try it and post if it solves the problem.
Thanks in advance
[2047 byte] By [
wololow] at [2007-9-27 16:03:53]

Well I tried other versions of the plug in and they seem to have the same problem. But I have noticed that images loaded using Applet.getImage() were displayed without problems. And when I ran the server/client locally "without" JARing the files, the images displayed perfectly.
I am using a load image method that I picked up from the forums to enable the loading of images from jars when using netscape. This is the code I use to load the images from JAR:
/** get an image from anyt sorce.*/
public Image getImageFromJAR(String fileName){
if (fileName == null) {
return null;
}
Image image = null;
byte[] thanksToNetscape = null;
Toolkit toolkit = Toolkit.getDefaultToolkit();
java.io.InputStream in = getClass().getResourceAsStream(fileName);
int x = 0;
try{
int length = in.available();
thanksToNetscape = new byte[length];
in.read( thanksToNetscape );
image = toolkit.createImage( thanksToNetscape );
}catch(Exception exc){
System.out.println( exc +" getting resource " +fileName );
}
return image;
}
> in.read( thanksToNetscape );
> image = toolkit.createImage( thanksToNetscape );
> }catch(Exception exc){
The method Toolkit.createImage() loads images asynchronously. Which means that when you return the Image back, it may not have been fully loaded yet. You could get around this by using the MediaTracker class to wait for it to load, like this:
image = toolkit.createImage(thanksToNetscape);
MediaTracker tracker = new MediaTracker(comp);// you need to give it a component
tracker.addImage(image, 0);
try
{
tracker.waitForId(0);
}
catch(Exception e) {}
-Eric
Thanx eric
I managed to solve the problem by loading images using:
cardImage = getAppletContext().getImage(cardImageUrl);
I removed all images from the jar file and are now downloaded from remotely. This might solve all compatability problems. But there actually seems to be a problem with:
getClass().getResourceAsStream(fileName);
it seems like it runs into a race condition, theres also poblems reported with .available() not returning the right size of the stream.