How can I communicate with an Object created in another JFrame?

Posted by user3093422 on Stack Overflow See other posts from Stack Overflow or by user3093422
Published on 2014-05-26T21:23:04Z Indexed on 2014/05/26 21:25 UTC
Read the original article Hit count: 85

Filed under:
|
|

so my program basically consists of two frames. As I click a button on Frame1, Frame2 pops up, and when I click a button on Frame2, and Object is created and the window closes. Now, I need to be able to use the methods of Object in my Frame1, how can this be achieved?

I am kind of new to Object-Oriented Programming, sorry, but it's hard to me to explain the situation. Thanks!

I will try to put a random code for pure example below. JFrame 1:

public class JFrame1 extends JFrame{

    variables..  

    public JFrame1(){

        GUIcomponents....

    }

    public static void main(String[] args) {
    JFrame1 aplicacion = new JFrame1();
    aplicacion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private class ActList implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            new JFrame2();
        }
    }
}

JFrame 2:

public class JFrame2 extends JFrame{

    variables..  

    public JFrame2(){

        GUIcomponents....

    }

    private class ActList implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            Object object = new Object();
            setVisible(false);
        }     
    }
}

Sorry if it's messy, I made it in the moment. So yeah, basically I want to JFrame1 to be able to use the getters and settes from Object, which was created in JFrame2. What should I do? Once again, thanks!

© Stack Overflow or respective owner

Related posts about java

Related posts about oop