Pause in Java/Swing ?

Schwartz

Expert Member
Joined
Feb 15, 2009
Messages
1,698
Reaction score
0
Hi guys,
I am practicing my programing and I am making a program where I want a 1 or 2 second delay.

eg: A card shows. 1 Sec later in disappears. I know how to make it show and disappear just not how to let the user have 1 sec to see the card!
Please help.. thanks :)

PS: I am using "Ready" as my IDE and Java/Java swing is my language.
 
You are going to need to use threads and make use of

Thread.sleep(1000); // Milliseconds of sleeptime

Also, change IDEs as soon as possible, Ready To Program was what we used to use in high school and it wasn't enjoyable (I remember we all brought our own IDEs into the final exams because of this).

Best of luck.
 
You are going to need to use threads and make use of

Thread.sleep(1000); // Milliseconds of sleeptime

Also, change IDEs as soon as possible, Ready To Program was what we used to use in high school and it wasn't enjoyable (I remember we all brought our own IDEs into the final exams because of this).

Best of luck.

k thanks.. will try that out.
Ready is what I learned at school so I have stuck with it! I know it is k@k though :(

EDIT: I am not using threads :(
any other suggestions?
 
also used Ready to Program in high school, was really crappy :)

You don't have to use threads to use Thread.sleep() since your program automatically runs in it's own thread.

just add the code
Code:
try {
   Thread.sleep(1000);
} catch (InterruptedException e) {

}
 
Nothing wrong with Ready for learning stuff at school, just a bit lame using it for anything else...
 
also used Ready to Program in high school, was really crappy :)

You don't have to use threads to use Thread.sleep() since your program automatically runs in it's own thread.

just add the code
Code:
try {
   Thread.sleep(1000);
} catch (InterruptedException e) {

}
thanks... but I am still not getting what I need..
I think it might be some other reason though :( It is pausing fine just not how I need it to.

For some reason the first card shows, then the pause then both disappear!
 
It's been a while since I used java and especially swing, however it sounds like it's a rendering issue.

ie:
- swing draws the controls in the window
- application thread pauses
- controls dissappear and aren't re-rendered
 
You should never Thread.Sleep on your UI thread, this is bad and will cause a horrible user experience such as repainting problems, which it sounds like you are having...

For what you are trying to achieve rather use javax.swing.Timer

EDIT: Oh and get Eclipse
 
You should never Thread.Sleep on your UI thread, this is bad and will cause a horrible user experience such as repainting problems, which it sounds like you are having...

For what you are trying to achieve rather use javax.swing.Timer

EDIT: Oh and get Eclipse

thanks

EDIT: Can you please show me how to implement it? like an example? because it is showing times is not found in environment :(
 
Last edited:
thanks

EDIT: Can you please show me how to implement it? like an example? because it is showing times is not found in environment :(

Sorry dude, don't know how to use it, we only had AWT when I was at varsity, that come up in a Google Search (it's the first link), maybe look there...
 
Top
Sign up to the MyBroadband newsletter
X