我现在在写一个swing gui,要用到线程,具体就是,如何让我创建的线程在jtextarea里一行一行的延迟打印出来!我用了sleep()方法,但是为什么还是一起出来的 看看部分代码
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
final int block=Integer.parseInt(blockTextField.getText());
final int total=Integer.parseInt(totalTextField.getText());
if(block>total)
warnningDialog.setVisible(true);// TODO add your handling code here:
else
{
String str=resultField.getText();
String array=str.substring(9);
char []arr=array.replace(" ", "").toCharArray();//arr[]数组现在存放着访问页面序列
char []lose=new char[block];
int flag=0;
class loseSquence extends Thread
{
String sname;
public loseSquence(String sname)
{
this.sname=sname;
}
public void run()
{
resultField.append(sname);
} }
loseSquence []List=new loseSquence[total];
for(int i=0;i<total;i++)
{
List[i]=new loseSquence("\n第"+i+"次淘汰页面序列为");
}
for(int i=0;i<total;i++)
{
try {
List[i].sleep(7000 * i);
List[i].start();
} catch (InterruptedException ex) {
Logger.getLogger(Operation.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
final int block=Integer.parseInt(blockTextField.getText());
final int total=Integer.parseInt(totalTextField.getText());
if(block>total)
warnningDialog.setVisible(true);// TODO add your handling code here:
else
{
String str=resultField.getText();
String array=str.substring(9);
char []arr=array.replace(" ", "").toCharArray();//arr[]数组现在存放着访问页面序列
char []lose=new char[block];
int flag=0;
class loseSquence extends Thread
{
String sname;
public loseSquence(String sname)
{
this.sname=sname;
}
public void run()
{
resultField.append(sname);
} }
loseSquence []List=new loseSquence[total];
for(int i=0;i<total;i++)
{
List[i]=new loseSquence("\n第"+i+"次淘汰页面序列为");
}
for(int i=0;i<total;i++)
{
try {
List[i].sleep(7000 * i);
List[i].start();
} catch (InterruptedException ex) {
Logger.getLogger(Operation.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
解决方案 »
- 我已经重写hashCode方法和equals方法还是不能判断两个重复的对象?
- com.sun.net.ssl.internal.ssl.Provider使用的错误
- hibernate 删除问题,在线等
- hibernate 的不明错误
- myeclipse 6.5中的代码延迟现象
- restful+jax-rs+eclipse3.5的问题
- 问个EJB调用的问题。。。
- 如何控制选值查询序列间的序列排查不报:严重: Servlet.service() for servlet jsp threw exception .....
- hibernate级联删除,我总是出错
- 大哥大姐们,救命啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 弱弱问个问题关于ssh各种包的问题
- hibernate映射问题
List[i]=new loseSquence("<br/>第"+i+"次淘汰页面序列为");
List[i]=new loseSquence("第"+i+"次淘汰页面序列为\n");