Now I fixed the problem - this is the code that works
public BufferedImage loadImage(String fileName){
BufferedImage buff = null;
try {
buff = ImageIO.read(getClass().getResourceAsStream(fileName));
} catch (IOException e) {
e.printStackTrace();
return null;
}
return buff;
}
The fileName value is simply the name of the image, for example, BufferedImage img = loadImage ("background.png");
Thank you all for your help.
source
share