I am not sure if I am referring to the right location with this code, the images I am trying to access are titled Flower0.png
etc.
They are located in the same directory as the rest of my code for this project.
This class is in a src folder called hangman.ui
and the .png
files are located in a directory folder called Resources
.
Perhaps getClass().getResource
is not right?
This is my first time trying to put images into a GUI.
Help is much appreciated!
public WiltingFlowerRendererRemix(HangmanLogic logic)
{
panel = new JPanel();
panel.setLayout(new BorderLayout());
imageLabel = new JLabel();
panel.add(imageLabel, BorderLayout.CENTER);
int numberOfImages = 10;
images = new ImageIcon[numberOfImages];
for (int i = 0; i < numberOfImages; i++)
{
images[i] = new ImageIcon(getClass().getResource("Flower"+Integer.toString(i) + ".png"));
}
}