delay

Hello, how to delay appilcation, let it wait for some amount of time?I tried wait(), but i got IllegalMonitorStateException.What should i do?
[162 byte] By [bobiseka] at [2007-11-27 4:54:32]
# 1
That exception says "Current thread not owner"
bobiseka at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...
# 2
Thread.sleep(long ); write a( throw Exception )
typeHa at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...
# 3

consider using Thread.sleep(miliseconds);

class Fubar1

{

public static void main(String[] args)

{

try

{

Thread.sleep(2000);

System.out.println("hello there!");

Thread.sleep(3000);

System.out.println("hello there again!");

}

catch (InterruptedException ie)

{

ie.printStackTrace();

}

}

}

petes1234a at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...
# 4

thx but there seems to be problem.

I have a single jframe with textbox.

I have while cyclus which goes trough text and highlights some character which match some pattern. i need to wait after each highlight, because user needs to see it. when i used thread sleep, the program waited, but no highlighting was visible, only when cyclus ended, the last highlight was visible. What could be the problem?

bobiseka at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...
# 5
I think that you'll have to hope that a swing GUI thread guru will read this message thread and enlighten us all. Til then, can you show a small bit of compilable code that illustrates your problem? Also, consider posting this in the Swing forum.Good luck!/Pete
petes1234a at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...
# 6
Maybe it is another pronlem? Maybe i have to call focus or redraw to my frame from inside of cyclus? Or is there any other solution? Please respond.
bobiseka at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...
# 7
Since the GUI and the program code should be in different threads.You can have one thread wait until the sleep is over while allowing the other thread to do text processing and GUI refreshing.Look at SwingUtilities.invokeLater.
TuringPesta at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...
# 8
Hi,I supose you are stopping the awt-Thread with the sleep.Try to create a new Thread for changing the highlight and sleeping with Thread.sleep
S_i_m_ua at 2007-7-12 10:09:14 > top of Java-index,Java Essentials,Java Programming...