Why are you creating an internal JWindow
when your class CreateSplashScreen
already extends JWindow
?
There is no need of it. You are messing with your program.
How?
You are actually viewing the inner JWindow
by jw.setVisible(true);
but you are painting the image in the CreateSplashScreen
's `JWindow.
Try this code :
public class CreateSplashScreen extends JWindow
{
ImageIcon i = new ImageIcon(getClass().getResource("/createsplashscreen/testImage.png"));
public CreateSplashScreen() {
setSize(700, 500);
setLocationRelativeTo(null);
setVisible(true);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(i.getImage(), 0, 0, null);
}
public void CloseSplashScreen() {
setVisible(false);
}
public static void main(String[] args) {
CreateSplashScreen sp = new CreateSplashScreen();
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
}
sp.CloseSplashScreen();
}
}
Note: I do not know about your method to fetch image resource from the source folder.
Edit: Assuming that the name of the package containing your class CreateSplashScreen
is createsplashscreen
, make sure that the image testImage.png
is present in the createsplashscreen
package of your project.