I am building a Java Swing gui and I am wondering what the best way of managing all my images would be. So far I have just been creating images from different classes whenever they are needed, by pointing out the path of each one, for example:
ImageIcon temp= new ImageIcon("resources/pictures/temp.png");
There are 2 things I don't like. First thing would be having all those paths. Second would be that I would prefer a more like "central repository" approach. Does anyone have a better practice to suggest, I was thinking maybe something like an ImageManager that loads all the images at the very start of a program. Can property files help somehow (never used them) with all those paths?
preguntado el 24 de agosto de 12 a las 19:08
Properties can be used for defining some key=value where key would be a unique key and value would be a path to the image. Then, as you suggested, you could use an ImageManager that could define methods that would get a key as a parameter and would return a reference to an ImageIcon or whatever the image type must be.