On 11=BF=F926=C0=CF, =BF=C0=C0=FC5=BD=C305=BA=D0, "Matt Humphrey" <ma...@ivi=
"jlc488" <jlc...@gmail.com> wrote in message
news:ccf4ff34-ec32-41bc-aace-46bcf6246c1b@b40g2000prf.googlegroups.com...=
On 11?25?, ??9?51?, "Matt Humphrey" <ma...@iviz.com> wrote:
Being threadsafe simply means that setText can be called from another
thread--your loop is still blocking the EDT. Andrew's version works
because
the main thread is not the EDT whereas "gogo" is invoked on the EDT,
blocking it until the loop ends. For GUI updates to be visible while
they
are in progress they must be activated from a different thread so that=
the
EDT can keep up the job of updating the screen.
Matt Humphreyhttp://www.iviz.com/-?? ??? ??? -
- ?? ??? ?? -
oh...ok...if it is that case what should i do ??
any suggestions?? matt??
You have to perform the action in a separate thread, like in the following=
example.
private void gogo(){
Thread t = new Thread (new Runnable () {
public void run () {
try{
for (int i = 0; i < 100000; i++) {
this.txtNo.setText(i+"");
}
}catch(Exception e ){ e.printStackTrace (); }
});
t.start ();
}
This works only for threadsafe methods like setText. Virtually everything=
else (except repaint) is not threadsafe and you must perform the actual
update in the EDT. (Confusing, yes? Time-consuming task code must NOT be=
in EDT, update code MUST be in EDT). The example provided by Andrew shows
how to use SwingWorker to setup a thread to do the working off the EDT and=
it manages to do the done method in the EDT. Also, that example shows the=
correct way to launch a GUI in the EDT rather than in the main thread.
http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html
Matt Humphreyhttp://www.iviz.com/- =B5=FB=BF =C5=D8=BD=BA=C6=AE =BC=FB=
thanks..it really helped me a lot...