Guys,i want to wait or sleep statement in a Java Desktop application when button press.I used thread.sleep & wait().But it doesn't work.I have a doubt that those functions are working only for console applications.Is it? or can i use it?Plz help me....

Recommended Answers

All 5 Replies

Guys,i want to wait or sleep statement in a Java Desktop application when button press.I used thread.sleep & wait().But it doesn't work.I have a doubt that those functions are working only for console applications.Is it? or can i use it?Plz help me....

Its not about type of applcation. Whether it is console or GUI , it doesn't matter.
Thread.sleep will work for all..

I guess you have some mess in your code. Post your code if you want to resolve your issue...

don't use Thread#sleep(int) for GUI, because could be generated unexpected output to the GUI, that's for Thread, Executor

for GUI is there javax.swing.Timer

Sleeping in a Swing GUI usually stops everything from working by blocking the Event Dispatch Thread ("Swing thread") on which Swing handles everything. Its never a good idea. Use a javax.swing.Timer to implement delays and repeated processes.

@mKorbel: snap! J

Thnx guys for your help.I think now i can solve the issue....:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.