Invoke a method of a JFrame from a JInternalFrame without do a new Instance

I have a little big problem doing this:

From a JFrame, I call a JInternalFrame, so, I want to call a method of the JF from the JIF. The problem is, if I make a new instance of this JF, the changes are not applied, because it's not the same original instance.

I'm doing a login in this JIF, if the credentials are right, the menu in the JF must change, otherwise, no change must be applied.

I read in other sites on Internet that "Invoke" is the solution, but "Invoke" apparently works only with new instances. Is there another solution?

answer:

Thanks everybody for his help!

I've solved the problem!

Generally to call all my JInternalFrames I used a general global declaration:

private JInternalFrame jif;

But to solve my problem, I declared a new constructor using directly the class of my JInternalFrame:

private LogInJInternalFrame logIn;

Before the call, I declared a public global constructor in the Log In JIF:

public MainJFrame mainJF;

With that, using the new constructor in my JF, I could able to access to all the public declarations in my JIF. Then, I made the call using something like this:

private void logInCall(){ logIn = new LogInJInternalFrame(); //--New instance of my JIF logIn.mainJF = this; /*Set the class to the constructor instead to declare a new one*/ logIn.setVisible(true); }

After that, in my JIF, when the credentials were right, I've used this:

mainJF.setNewUserMenu(); /*The class's instance let me "invoke" the method I've wanted*/

And that's all, after the results all I can said was "I really need to relax more and think better the things".

Thanks again!!!

sumber:
http://stackoverflow.com/questions/20645369/invoke-a-method-of-a-jframe-from-a-jinternalframe-without-do-a-new-instance

Tidak ada komentar:

Diberdayakan oleh Blogger.