请问下,我的程序里面有frame1和fream2两个窗体;我在frame1中通过一个按钮事件调用frame2,
这时frame2里有一系列的jtextfield,当填入数据后,却无法通过frame2中的按钮事件写入到bean中。请问下,这时事件监听还停留在frame1中吗?

解决方案 »

  1.   

    又仔细看了下,确认是swing jtextfield
    事件监听只要注册了不移除就都在,
    无所谓停留不停留的问题
    直接在frame2中注册按钮事件写bean么
      

  2.   

    恩,frame2中有个BUTTON,我想通过点击button把textfield中的数据写入到bean中。但是没成功我测试了在里面直接用System.out.print也没有成功打印出信息
      

  3.   

    有点疑惑是不是,注册事件还一直在监听frame1而没有监听frame2中的组件
      

  4.   

    import javax.swing.* ;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;public class frame1 extends JFrame
    {
    private JButton btn ; public frame1()
    {
    setSize(200,200);
    setLocation(100,100);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true); btn = new JButton("aaa");
    this.add(btn);

    btn.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource() == btn )
    {
    new frame2();
    System.out.println("call frame2");
    }
    }
    });
    } public static void main(String args[])
    {
    new frame1();
    }
    }
    import javax.swing.* ;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;public class frame2 extends JFrame
    {
    private JButton btn ; public frame2()
    {
    setSize(200,200);
    setLocation(100,100);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true); btn = new JButton("bbb");
    this.add(btn);

    btn.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource() == btn )
    {
    new frame1();
    System.out.println("call frame1");
    }
    }
    });
    }}但是写了个DEMO,也没有问题。