1    import javax.swing.*;
2    
3    public class ThreadMessage extends JLabel implements Runnable {
4    
5      String text = " ";
6    //  String pretext = " ";
7    //  int numval;
8    
9      boolean pending = false;
10   
11     public ThreadMessage() {
12       super();
13       super.setText(text);
14     }
15     public ThreadMessage(String lab) {
16       super(lab);
17       text = lab;
18     }
19   
20     public void setText(String newtext) {
21       synchronized (this) {
22         text = newtext;
23         if (pending) return;
24         pending = true;
25       }
26       SwingUtilities.invokeLater(this);
27     }
28   
29   
30     public void run() {
31       synchronized (this){
32         super.setText(text);
33         pending = false;
34       }
35     }
36   }
37