Hello. I have 3 classes ;
main.java
calls
gui.java

Gui g =new Gui(); 
g.createAndShowGUI();

Then I have my menu.java with the actionPerformed()
I am trying to call methods of the GUI.java

How can I call methods on the GUI.java to
and use the methods on that instance of the
GUI.java?

I tried using

GUI g =new GUI();
g.performTask();

but this creates a brand new class.

You need to keep the reference 'g' at class level or pass it to methods that need to act on it.

Edited 6 Years Ago by Ezzaral: n/a

You need to keep the reference 'g' at class level or pass it to methods that need to act on it.

This brings a few concepts I need to understand.

if the GUI.java is left at class level after it is created then:

My menu.java should extend it? this will allow it to use its methods?

also:

if my GUI.java happened to be a panel with components on it.
and if this panel was on a tabbedpane which was one of serveral innerFrame on a JDesktop.

I would have to somehow get an instance of the frame that had focus or basically if it was the frame I wanted the menu to perform the method of its instance

is this what you mean as far as the GUI.java would have to be passed to the menu.java class?

This brings a few concepts I need to understand.

if the GUI.java is left at class level after it is created then:

My menu.java should extend it? this will allow it to use its methods?

also:

if my GUI.java happened to be a panel with components on it.
and if this panel was on a tabbedpane which was one of serveral innerFrame on a JDesktop.

I would have to somehow get an instance of the frame that had focus or basically if it was the frame I wanted the menu to perform the method of its instance

is this what you mean as far as the GUI.java would have to be passed to the menu.java class?

The reason I'm trying to get the concepts straight is because I built a simple JDesktop pane and I was forced to move all my menu class into the GUI class because I did not know how to call methods from class to class with out instantiating a new GUI.

so I will try to figure extending it and finally learn to use super.

but when the menuitem is selected I don't understand how it knows which internalFrame (instance of gui) to be working on.

This article has been dead for over six months. Start a new discussion instead.