I'm relatively new to Java programming and here is some code where it should draw a background Image:
public class Board extends JPanel{
private static final long serialVersionUID = 4759318639631503071L;
public String room = "menu";
public Image backgroundImage;
public Image getBackgroundImage() throws IOException{
if (room == "menu") {
backgroundImage = ImageIO.read(new File("assets/background_title.png"));
}
return backgroundImage;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(backgroundImage, 0, 0, this);
}
}
I used System.out.println and realized that backgroundImage was null, what have I done wrong here?