我建议这样:
MainFram 不需要多线程,你的监听器和MainFram 可以通过观察者模式实现监听和界面及时显示的功能,在MainFram 的事件中repaint FRAME即可

解决方案 »

  1.   

    写了个简单的例子,没有测试过,希望对你有帮助FRAME类:
    /*
     * MainFrame.java
     *
     * Created on __DATE__, __TIME__
     */package learning.swing;/**
     *
     * @author  __USER__
     */
    public class MainFrame extends javax.swing.JFrame { private String content="no content";
    private ListenerClass listener;//你的监听类

    public String getContent() {
    return content;
    }
    public void setContent(String content) {
    this.content = content;
    } /** Creates new form MainFrame */
    public MainFrame() {
    initComponents();
    }

    public MainFrame(ListenerClass listener) {
    initComponents();
    this.listener=listener;//注册
    }

    public void refresh(String text){
    this.setContent(text);
    jTextArea1.setText(this.content);
                    repaint();
    } /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jTextArea1.setText(this.content); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1); getContentPane().add(jScrollPane1,java.awt.BorderLayout.CENTER); pack();
    }// </editor-fold>
    //GEN-END:initComponents /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
                    MainFrame testtt=new MainFrame();
                    ListenerClass test=new ListenerClass();
                    test.register(testtt);
    java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
    testtt.setVisible(true);
    }
    });
    } //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables}监听类
    public class ListenerClass{
       MainFrame frame=null;   public ListenerClass(){
       }   public void register(MainFrame frame){
          this.frame=frame;
       }
       
       public eventOccur(){//事件触发
         this.frame.refresh("change text");
       }
    }之后执行eventOccur()就应该可以了
      

  2.   

     bandaiwy  非常感谢你的回答 MainFram 不需要多线程,你的监听器和MainFram 可以通过观察者模式实现监听和界面及时显示的功能,在MainFram 的事件中repaint FRAME即可但这句话的意思小弟还没搞明白.可以说具体一点..什么是观察者模式? 
     
      

  3.   

    Observer(观察者)模式是比较常用的一个模式,尤其在界面设计中应用广泛
    java api 提供Java.util.Observer接口
      

  4.   

    你可以下个<java设计模式看看>
      

  5.   

    单例模式:public class JbInit { private JbInit() {
    System.out.println("一个图形界面!");
    } private static JbInit instance = new JbInit(); public static JbInit getInstance() {
    return instance;
    }
    }
    调用时 JbInit.getInstance()保证只实现一个JbInit实例。