I’m trying to make a loader screen in java. So far I’ve managed to successfully make a splash screen for my program, the splash screen works fine.
I’ve used the same code to create the loader but when I call the object only the sleep part works, I mean nothing really appears on the screen.
public class IL extends JWindow {
Image L=Toolkit.getDefaultToolkit().getImage("L.png");
ImageIcon LI=new ImageIcon(L);
public IL (){
try
{
setSize(LI.getIconWidth(),LI.getIconHeight());
setLocationRelativeTo(null);
show();
Thread.sleep(10000);
dispose();
}
You’re blocking the UI thread with that
sleep, essentially preventing it from displaying anything.You should use a timer for this. See How to Use Swing Timers and the Swing
TimerAPI docs. You use a timer to do the hide/dispose after however much time you want. You could also use that timer to display a progress bar or animate your loader page.