I usually load images in Applets using:
this.getImage( getCodeBase(), "myimage.png" );
or
myapplet.getImage( getCodeBase(), "myimage.png" );
But what if I want to load an image from another class which is not a child of Applet, neither does it have a member which refers to the Applet?
Say, I have a sprite class, in whose update method I want to load images for animation:
@Override
public void update(){
frame++;
if ( frame > 3 ) frame = 1;
/* the problem */
loadImage( getCodeBase(), "myimage_" + frame + ".png" );
}
Of course I could include Applet app as parameter, but the sprite’s update method gets called in so many different parts of the code and in so many other classes, that it will extremely complicate stuff and make life difficult.
So is there a way I can load an image from a file in an applet without using the applet’s getImage() method?
1 Answer