there are several ways to do that...for example, you can build the first frame and then use the first frame as the parameter of the second frame.Then you can write getXXX() or setXXX() methods to access the variables of the other frame. That helps information encapsulation. Don't access those variables directly by frame.XXX. That's not a good habit.

解决方案 »

  1.   

    A more meaningful and significant way is to write a eventlistener when information is needed to be transmitted as an event happened. 
    That may not be the best way in code efficiency but likely the most readable program architecture.
      

  2.   

    可以用引用,
    比如在frame2的对象里面看到frame1的东西:
    class frame1{
    main(){
    ......
    frame2 vv=new frame2;
    vv.yy=this;
    ........}
    }class frame2{
    frame1 yy; 
    }
      

  3.   

    但是如果是用new,好象出来的变量的值是不同的?怎么办呢?
      

  4.   

    你肯定要用一个变量保存一个窗体,把这个变量赋值给另外一个窗体的成员变量,就向boancqu所说的,另外一个窗体就可以访问这个窗体了。
      

  5.   

    很多方法:
    1.构造函数
    2.static
      

  6.   

    唉,说了半天,原来没看懂,呜呜。
    只好在说一遍啦。
    你可以用getXXX()和setXXX()方法来访问另外一个类的变量。
    譬如说,那个类有一个JTextField类的field变量。那么写public JTextField getField()
    {
      return this.field;
    }public void setField(JTextField field)
    {
      this.field = field;
    }然后把这个类的一个实例作为参数传递给第二个类的实例;
    假使第二个类的构造方法是这样的。
    public Frame2(Frame frame1)
    {
      this.frame = frame1;
    }
    那么在这个第二个类的实例中就可以这样访问第一个类的field变量。
    JTextField field2 = frame.getField();
    or
    frame.setField(new JTextField("另外一个TextField"));如果涉及到事件侦听的话,最好采用EventListener接口的办法,这样的话,可以使结构更加***。不过现在就不用考虑了。