如何将线程里连续得到的值在GUI里显示回来? 一个GUI。像另建一个类创建线程。然后次线程连续的收取一个INT的值。我现在希望在收到以后,能显示到GUI里。怎么才能显示呢? GUI用的是JTextPane, 是个PRIVATE。没法再线程那边调用并且显示啊。

解决方案 »

  1.   

    http://www.microblue.com.cn/it/3958.html
      

  2.   

    很esay..我给你个动态显示时间的例子吧。。不想写代码了。
    import java.awt.Font;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;import javax.swing.JLabel;public class Time implements Runnable{
    private JLabel label;
    public Time(JLabel label){
    this.label=label;
    }
    public void run(){
    while(true){
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   
    String time=dateFormat.format(new Date());
    label.setText("当前时间:"+time);
    label.setFont(new Font("微软雅黑",Font.BOLD,16));
    try{
    Thread.sleep(1000);
    }catch(Exception e){
    label.setText("系统时间暂时无法显示");
    }
    }
    }
    }
    以上是定义时间的线程。。
    然后在Panel设个jlabel然后调用JLabel time=new JLabel();
    new Thread(new Time(time)).start();
      

  3.   

    写个构造方法或者用set、get获取