大家好,小弟做程序的时候遇到下面的问题,希望谁能帮帮忙!
我在Client窗口(JFrame)中打开了一个Chat窗口,
我想在Chat窗口中进行相关操作时,Client窗口能根据我的行为来刷新。
比如说:我想在Chat窗口里修改Client窗口的标题。
修改之后,Client能立即刷新

解决方案 »

  1.   

    class Client extends JFrame
    {
    public void newChat  //生成新的chat窗口
    {
    Chat chat = new Chat();
    chat.setClient(this);
    }
    public void doSomething()  //chat有相关操作时client的动作
    {
    //your action here
    }
    }class Chat extends JFrame
    {
    Client client;
    public void setClient(Client c)
    {
    client = c;
    }
    public void doSomething()  //chat相关操作
    ...
    client.doSomething();
    ...
    }
    }
      

  2.   

    首先,你的Chat窗口的构造函数应该包含父窗口Client,如:
    public Chat extends JFrame{
        JFrame client;
        public chat(JFrame client){
            this.client = client;
            ....//具体的构造
        }
        
       public void action(){
         //具体的操作
         //刷新Client   }
    }
      

  3.   

    可以让你的Chat窗口返回值啊,然后在你的Chat窗口的关闭事件中对Client窗口进行刷新
    或者直接在Chat窗口中将Client的实例传进 去