日期:2014-05-20  浏览次数:20646 次

关于延时显示的问题
我想用一个循环,分别在三个文本域(jTextAreaNo1,jTextAreaNo2,jTextAreaNo3)输出三个字符串(mem1,mem2,mem3)。
我想要的效果是:
jTextAreaNo1先显示mem1的第一个字符,然后jTextAreaNo2显示mem2的第一个字符,然后jTextAreaNo3显示mem3的第一个字符;
jTextAreaNo1再显示mem1的第二个字符,然后jTextAreaNo2再显示mem2的第二个字符……依次下去。
目的是:
模拟字节多路通道程序分时为3个设备服务。
我是这样做的:
int   i;
for(   i=0;i <mem1.length()   ||   i <mem2.length()   ||   i <mem3.length();i++){
    if(i <mem1.length()){
        jTextAreaNo1.append(String.valueOf(mem1.charAt(i)));
    }else{
        jTextAreaNo1.append(String.valueOf( "   "));
    }
    for(int   j=0;j <999999999;j++);

    if(i <mem2.length()){
        jTextAreaNo2.append(String.valueOf(mem2.charAt(i)));
    }else{
        jTextAreaNo2.append(String.valueOf( "   "));
    }
    for(int   j=0;j <999999999;j++);

    if(i <mem3.length()){
        jTextAreaNo3.append(String.valueOf(mem3.charAt(i)));
    }else{
        jTextAreaNo3.append(String.valueOf( "   "));
    }
    for(int   j=0;j <999999999;j++);
}

用了   for(int   j=0;j <999999999;j++);希望能达到“分时显示”的效果。
但实际效果是,程序停顿了一会儿,然后三个文本域同时把内容显示出来了。
我把   for(int   j=0;j <999999999;j++);换成wait()、sleep()也未达到想要的效果。
请问要怎么改进?请大家多多指教。十分感谢。
——————————
所有的源代码:

import   java.awt.*;
import   javax.swing.*;


public   class   MainBoard   extends   JFrame   {

private   static   final   long   serialVersionUID   =   1L;
private   JMenuBar   jJMenuBar   =   null;
private   JPanel   jPanel   =   null;
private   JToolBar   jJToolBarBar   =   null;
private   JButton   jButton   =   null;
private   JButton   jButton1   =   null;
private   JButton   jButton2   =   null;
private   JLabel   jLabelState   =   null;
static   String   mem1   = "love ";  
                static   String   mem2   = "study ";
                static   String   mem3   = "wahaha ";    
private   JTextField   jTextFieldCPU   =   null;
private   JPanel   jPanel1   =   null;
private   JTextArea   jTextAreaNo1   =   null;
private   JTextArea   jTextAreaNo2   =   null;
private   JTextArea   jTextAreaNo3   =   null;
/**
  *   This   is   the   default   constructor
  */
public   MainBoard()   {
super();
initialize();
}

/**
  *   This   method   initializes   this
  *  
  *   @return   void
  */
private   void   initialize()   {
this.setSize(521,   217);
this.setContentPane(getJPanel());
this.setJMenuBar(getJJMenuBar());
this.setTitle( "字节多路通道处理模拟 ");
}

/**
  *   This   method   initializes   jJMenuBar
  *