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

[1715 byte] By [suhua] at [2007-11-27 10:38:42]
# 1

you've posted here 56 times and don't use code tags? c'mon, you can do better than that!!

Oh yes, I remember you:

http://forum.java.sun.com/thread.jspa?threadID=5187356&messageID=9731958#9731958

Good luck

Message was edited by:

petes1234

petes1234a at 2007-7-28 18:56:08 > top of Java-index,Java Essentials,New To Java...
# 2

Thread.sleep(20000); //sleep 10 seconds

This is my favorite line.

CaptainMorgan08a at 2007-7-28 18:56:08 > top of Java-index,Java Essentials,New To Java...
# 3

> Thread.sleep(20000); //sleep 10 seconds

> This is my favorite line.

There are three types of people in this world: those that understand mathematics, and those that don't.

petes1234a at 2007-7-28 18:56:08 > top of Java-index,Java Essentials,New To Java...
# 4

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

suhua at 2007-7-28 18:56:08 > top of Java-index,Java Essentials,New To Java...
# 5

OK

10 or 20 seconds is important?

it is only error of copy and paste

petes, you already posted nearly 2000 posts. I remember that when you replied my post, your posts are only <1000

suhua at 2007-7-28 18:56:08 > top of Java-index,Java Essentials,New To Java...