我用的地理布局,这个无所谓了.
每个区域都是个JPanel,现在有个问题,我在右区域的JPanel中有个buttom
我想在按下这个buttom时取其它区域text部件的数据,并在中间区域的JPanel的某个部件接收事件,以完成功能,可我只知道在同类中传递事件,所以程序就卡在了这里,请高手帮忙
小的感激不尽...

解决方案 »

  1.   

    不是中间接收事件,是在JButton事件中设置中间的内容。
    比如中间的JPanel中有个JLabel,监听JButton事件,当发生事件后使用label.setText("ABCD");方法将内容显示出来。
      

  2.   

    你的JPanel放置在什么容器上的?
    你在这个容器里设一个中间的量,作为“桥梁”就可以了啊
      

  3.   

    比如JPanel1和JPanel2都放在一个JFrame上面
    那么你就
    JPanel1上   set变量 --->JFrame上变量 --->JPanel2上   get变量
    不知道你能看懂吗?
      

  4.   

    每一个Jpanel都是一个对象,通过控制这些对象的方法调用,就能达到你想要的效果.
      

  5.   

    中间JPanel中写一个pulic方法:getComp()返回接收数据的部件。右边JPanel写一个JButton的事件响应
    在事件响应里将得到的数据用getComp()得到的部件接收其他部件写public:getData()方法,用来得到getComp()返回部件所接受的数据
      

  6.   

    如果getComp()得到的部件在接收数据后发生改变。
    可以在中间JPanel中写个pulic void setComp(type comp);
      

  7.   


    public class B extends JPanel{   public void onOk(){
            System.out.println("I get it!");
       }
    }public class C extends JPanel{
      private B receiver = null;
      public C(B receiver){
         this.receiver = receiver;
         JButton btnOk = new JButton("OK");
         btnOk.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                 onOk();
            }
         }
         this.add(btnOk);
      }  private void onOk(){
         receiver.onOK();
      }
    }
      

  8.   

    在你button的事件里写button.getParent()找到上一级 一层一层找!