Hey, I was hoping someone could point out why my image may not be showing. Note I am using eclipse.
Window.java:
import javax.swing.*; public class Window { private JFrame gameWindow; public Window() { gameWindow = new JFrame("Tamagotchi!"); gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gameWindow.setBounds(0,0,800,600); SplashScreen splashScreen = new SplashScreen(); gameWindow.add(splashScreen.getContent()); gameWindow.setVisible(true); } public static void main(String[] args) { new Window(); } }
SplashScreen.java:
import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; public class SplashScreen { private JPanel splashPanel; private JLabel background; private ImageIcon backgroundImage; public SplashScreen() { splashPanel = new JPanel(); backgroundImage = new ImageIcon("splash_screen.png"); background = new JLabel(backgroundImage); splashPanel.add(background); splashPanel.setBounds(0,0,800,600); } public JPanel getContent() { return splashPanel; } }
I have used file.exists() and this returns true, and file.length() which returns the correct file size.
System.out.println(backgroundImage) returns "splash.png" so thats ok.
Why then is my image not showing?
Thanks for reading.