I have a Player class, a Weapon class and a Projectile class in my applet game.

The weapon class uses Projectile objects when fired.

For example, everytime I click I want this code to execute:

projectileList.add( player.weapon.fire() );

player.weapon.fire() returns one or more projectiles that the projectileList handles every frame.
In every frame, the projectileList should render all the projectile objects in the list, like this:

for(int i = 0;i<projectileList.size();i++){
                projectileList.get(i).draw(g, this);

"g" is the Graphics object, and "this" is the image observer.
That's basically what I want to do; simply define the images inside the projectile class, so I can simply use them in a weapon class, like this:

myWeapon.projectile = new Projectile(Projectile.bullet);

But I have no idea how I define images inside the projectile class.

The only image loading code that seems to work for me is this one:


These aren't working at all:

new ImageIcon("bullet_machinegun.png").getImage();

Do you have any ideas on how to make this work?

7 Years
Discussion Span
Last Post by Acegikmo

I'm really stuck right now and won't get far if I don't solve this issue. :(


in the 2 later methods, you have to supply the full path. you have to get the string version of the URL returned by getCodeBase(), and tack it onto the front of the image file name.

I think that should work, I don't know much about the URL class....

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.