simple slashscreen - how it work
Hello all
I have a splash screen that will display 10 seconds. I have two ways to do that. I think that the first way is correct but when I run, the first way is WRONG (the screen is shown only about 0.1 second). I think that the second way is wrong, but it runs well. Could you please help
====================================
// FIRST WAY
public class SplashScreen implements Runnable {
public void run (){
showSplash();
try {
Thread.sleep(20000);//sleep 10 seconds
} catch (InterruptedException ex) {
ex.printStackTrace();
}
return;
}
private void showSplash(){
..
}
}
//This does not work !!!!!!!
//Note that this main function runs in another main class
public static void main (String[] args){
Thread aThread = new Thread(new SplashScreen());
aThread.start();
..
}
===========================================
//SECOND WAY - WORK WELL
public class SplashScreen implements Runnable {
public void run (){
showSplash();
}
private void showSplash(){
..
}
}
//this main function runs in another main class
public static void main(String args[]) {
SplashScreen splash = new SplashScreen();
Thread thread = new Thread (splash);
try {
thread.start();
thread.sleep(20000);
thread.interrupt(); // the application still works when I remove this line
}
catch (Exception e){
System.out.println("Error when open splash screen");
}
}
============================
I do not know why.
Thank you for your help
suhu

