.......
JTextField jtf = new JTextField();
.......class TM extends Thread{
long start = System.currentTimeMillis();
public void run(){
while(true){
int time = (System.currentTimeMillis() - start) / 1000;
jtf.setText(time + "sec");
try{
sleep(1000);
}catch(InturrptedException e){}
}
}
}//somewhere to do new TM().start() and don't forget to stop it
JTextField jtf = new JTextField();
.......class TM extends Thread{
long start = System.currentTimeMillis();
public void run(){
while(true){
int time = (System.currentTimeMillis() - start) / 1000;
jtf.setText(time + "sec");
try{
sleep(1000);
}catch(InturrptedException e){}
}
}
}//somewhere to do new TM().start() and don't forget to stop it
Pay attention to this.
2 在new线程时传入外面的父类句柄;
3 在run中调用updateText;