I read the applet game tutorial written by that German guy. However, the code he uses to display images doesn't seem to work. No image is displayed at all. I've looked my problem up at java.com and have been utterly astonished at the complexity of their answers. So anywho, I'm on Java 2, SE v1.4.2_06. The code I got from the tutorial was:
Loading images in applets (and sometimes in applications)
requires a few more code lines. The thing is that the code:
backImage = getImage(getCodeBase(), "land.gif");
doesn't get you the image right away, it has to download completely
to the client before you can display it. If you attempt to
draw it before all its bytes have arrived you'll see nothing
or just parts of it. So, you have to wait for it.
Provided that the image is really located at the applets codebase
you cold try this (I'm loading two images here just for
demonstration)
public void update(Graphics g) {
if (imagesOK) {
g.drawImage(backImageA, 0, 0, this);
} else {
g.drawString("Loading images",0,0);
}
}
public void paint(Graphics g) {
update(g);
}
If you are using IE, and you are not doing it already I recommend that you bring up the java console (tools->sun java console) and
check for exceptions stacktraces.
01-25-2005, 06:48 PM
cowman196
Aha! Success! You're a good person sjalle. Thanks for the extra code and the helpful little tidbits.
EDIT: ACH! It actually still refuses to work for larger images! For the little ball, the image displays correctly. However, the same technique still doesn't work on the other program with a large gif pic for the background.