Access an object method created in main class from another class
<p>Is it possible to access an object created in main class? or there is a way of get the owner/reference class?</p>

<p>For example, in the code below, how can I call the method <strong>setMenu</strong>, that is on the <strong>myMainClass</strong>, from one of the <strong>Menu</strong> class objects (<strong>firstMenu</strong>, <strong>secondMenu</strong>)</p>

<p>I can make the Menu objects static but doesn't seems like the right approach...</p>

<p><strong>Main Class</strong></p>

<pre><code>public class myMainClass extends JFrame {

    JPanel container;
    Menu firstMenu;
    Menu secondMenu;

    myMainClass() {

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 400);

        firstMenu = new Menu();
        secondMenu = new Menu();

        container = new JPanel(new CardLayout());
        container.add(firstMenu, "firstMenu");
        container.add(secondMenu, "secondMenu");

        add(container);
    }

    public void setMenu(String s) {
        CardLayout cl = (CardLayout) (container.getLayout());
        cl.show(container, s);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                myMainClass myMainClassObject = new myMainClass();
                myMainClassObject.setVisible(true);
            }
        });
    }
}
</code></pre>

<p><strong>Menu Class</strong></p>

<pre><code>public class Menu extends JFrame {

    Menu() {
        //How can I call myMainClass setMenu method from here?
        //myMainClass.setMenu("secondMenu");
        //myMainClassObject.setMenu("secondMenu");
    }
}
</code></pre>

<p>Thanks</p>
