使用计时器timer,可以实现,在计时器中设定时间,到达后关闭计时器,退出线程就行了。importjava.awt.*importjava.awt.event.*importjavax.swing.timerclassttimplementsactionlistener{tttttimertimepublictt(tttt){this.t=ttime=newtimer(1000,this)time.setrepeats(false)}publicvoidactionperformed(actionevente){time.stop()}}classtttextendsthread{tttempinti=0publicttt(){temp=newtt(this)}publicvoidrun(){temp.time.start()while(i