I swear I've looked everywhere and have been googling for hours. I have added actionListeners
to all buttons, and when one is clicked, I want to give it an image with setIcon( image )
like so:
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button) {
ImageIcon icon = new ImageIcon(getClass().getResource("/Images/" +letter+ ".PNG"));
button.setIcon(icon );
}
1) I know it's retrieving the image because button.getIcon()
gives me something like file:/Users/path/to/Images/X.PNG
. I've checked if it's null before and after I've set the icon and it's not null afterward.
2) I've tried other variations of setIcon besides getClass()...
and ImageIO.read...
and BufferedImage
.
3) I don't want to add more code because I'm not even sure what else is relevant. I was hoping for some of your speculations
4) In eclipse, I changed my output folder to src
(instead of bin
), and that's where my Images
folder is.