Splash Screen timer. ( I know its a dumb Q)

hi i am new to java and i am making a personal contact n bday reminder program for myself. i wanted to add a splash screen when i load the program.

i tried

Thread.sleep()

i tried to use System.currentTimeMillis() with a while loop.. but the problem being my splash screen doesnt show on teh screen untill AFTER the delay!..

i read the forums and people say its because i might not be using active renderring.. ok see i Only need the splash screen and am not making a game of anysort. is there a simple way to Display the splash screen for 3 secs and then run my program!!! :-)

oh i am using JWindow for a splash screen! :-)

please any help will be gladly welcomed!. :-)

thanks for entertaining a **** simple Q.

[764 byte] By [thyscorpiona] at [2007-11-26 17:06:02]
# 1
You admit it has nothing to do with games yet you post in the Games forum anyway? @_@ !Need to see your code and PLEASE use the code tags.
maple_shafta at 2007-7-8 23:33:50 > top of Java-index,Other Topics,Java Game Development...
# 2

for making the app sleep i am using the following code.

final JWindow win = new JWindow();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

win.setBounds((screenSize.width/2)-200, (screenSize.height/2)-100,

(screenSize.width/2)+210,

(screenSize.height/2)+110);

//......Other code

win.setSize(410,210);

win.setVisible(true);

win.setAlwaysOnTop(true);

long starttime = System.currentTimeMillis(),currenttime=System.currentTimeMillis();

while((starttime+5000) >currenttime)

{

currenttime=System.currentTimeMillis();

System.out.println("stime"+starttime);

System.out.println("ctime"+currenttime);

}

Ok now! the thing that i am bugged with is that the splash screen comes up AFTER the 5 second delay! and while i wanted the screen to be displayed for 5 secs! :-)

after reading a bit i realize that the screen is painted onto teh screen at the end and not at real time to teh jWindowObject.setVisible(true); line.. :-(

hope my code snip helps...

PS: sorry for posting it into the games heading.. i saw a lot of people discussing Timers under games and thought u guys would be able to help me better!

thyscorpiona at 2007-7-8 23:33:50 > top of Java-index,Other Topics,Java Game Development...
# 3

Well you basically just answered your own question. Your thread of execution is caught in this while loop which is preventing the window from being painted to your screen.

Try instantiating a javax.swing.Timer class.

The Timer object executes a particular piece of code at a given interval on a SEPERATE thread of execution. That way your welcome screen has time to paint to the screen and after 5 seconds it executes a particular snippet of code once.

final JWindow win = new JWindow();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

win.setBounds((screenSize.width/2)-200, (screenSize.height/2)-100,

(screenSize.width/2)+210,

(screenSize.height/2)+110);

//......Other code

win.setSize(410,210);

win.setVisible(true);

win.setAlwaysOnTop(true);

Timer timer = null;

ActionListener listenerObj = new ActionListener() {

public void actionPerformed(ActionEvent evt) {

timer.stop(); //Stops the timer after first execution

//Other code executed on seperate thread

}

};

timer = new Timer(5000, listenerObj);

timer.start();

maple_shafta at 2007-7-8 23:33:50 > top of Java-index,Other Topics,Java Game Development...