ImageLoader.

Well if you’ve seen my “Res Folder” post not long ago, you’d see my cluttered up code:

		// CloseButton
		URL jfBG = PatchNotesGUI.class.getResource("/PatchFrame/patchBG.png");
		URL bCD = PatchNotesGUI.class.getResource("/close/button_CLOSE.png");
		URL bCCD = PatchNotesGUI.class
				.getResource("/close/button_CLOSE_CLICK.png");
		URL bCH = PatchNotesGUI.class
				.getResource("/close/button_CLOSE_HOVER.png");

		URL lCB = PatchNotesGUI.class
				.getResource("/close/large//button_LARGE_CLOSE.png");
		URL lCC = PatchNotesGUI.class
				.getResource("/close/large//button_LARGE_CLOSE_CLICKED.png");
		URL lCH = PatchNotesGUI.class
				.getResource("/close/large//button_LARGE_CLOSE_HOVER.png");

is there a way I can make like ImageLoader.java, put all of these in it, then continue calling them in this class? like this:

		JButton Close = new JButton();
		Close.setIcon(new ImageIcon(bCD));
		Close.setSelectedIcon(new ImageIcon(bCCD));
		Close.setDisabledIcon(new ImageIcon(bCH));
		Close.setDisabledSelectedIcon(new ImageIcon(bCH));
		Close.setPressedIcon(new ImageIcon(bCCD));
		Close.setRolloverIcon(new ImageIcon(bCH));
		Close.setRolloverSelectedIcon(new ImageIcon(bCH));

is how I’ve been doing it. Any help would be nice, need to fancy it up and get rid of the clutter haha

You could make them static.


class Gfx {
   public static ImageIcon bCD = new ImageIcon(PatchNotesGUI.class.getRe....);
}

Close.setIcon( Gfx.bCD );

Sticking with the original method, doing statics or enums would work, but it would probably be faster to stick all your textures in one image, then load them like a sprite sheet (optimal if images have the same size) or use an atlas.

This OR use static imports :slight_smile: