Sure. This first snippet is a case when you are creating a new BufferedImage for every single object you make. Each object has their own image, and the image is loaded upon construction. This is the most obvious way to do things and is pretty much how you seem to be doing it.
public class Ship
{
private int x, y, width, height;
private BufferedImage image;
public Ship(int xPos, int yPos, int wid, int hi, String imageLoc)
{
x = xPos;
y = yPos;
width = wi;
height = hi;
try {image = ImageIO.read(imageLoc); } catch (Exception e) {e.printStackTrace();}
}
public void draw(Graphics g)
{
g.drawImage(image, x, y, width, height, null);
}
}
The second snippet is almost exactly the same but uses the ResourceManager. Every object has a key that points to an image loaded within the ResourceManager, which will only be loaded the first time you call it. In addition, having only one instance of that image is much much easier on your memory.
public class Ship
{
private int x, y, width, height;
private String image;
public Ship(int xPos, int yPos, int wid, int hi, String imageLoc)
{
x = xPos;
y = yPos;
width = wi;
height = hi;
image = imageLoc;
}
public void draw(Graphics g)
{
g.drawImage(ResourceManager.getImage(image), x, y, width, height, null);
}
}
See the difference? Typically you want to preload every image, by the way, I just didn’t include it in the code because it’s simple to do and would be up to you when you want to do it.