I have a JFrame, when I click a button on JFrame, it creates a new JInternalFrame having a 'Finalize' button. What I want is that, when I click the Finalize button the JInternalFrame disposes and send some values (data) to that JFrame which created the JInternalFrame.
How can I achieve this? any relevant example will be a great help to me.
Sorry I don't have much time to explain. basically what I do in the code below is pass to the constructor of the InternalFrame from the MainFrame. Those values are set from the IntrernalFrame, then does something with the value. I just did a messy GUI Builder demo, but you may also consider using setters and setters in your MainFrame and pass the entire MainFrame to the InternalFrame. Just an idea. You can run the program. I'll try and come back when I have time, for a better explanation.
EDIT
So I'm too lazy to make a real example without using the super messy looking Gui Builder code, so I'll explain the important parts. What you're trying to do is share objects. What you can do is pass then my reference through the constructor. What I did below was, from the
MainFrame
pass aJLabel
and aString
which will be altered by theInternalFrame
. When theFinalize
button is pressed, the changes will automatically be updated in theMainFrame
. Here's what the important code looks likeMainFrame
InternalFrame
This is one simple way of passing infomation. Complete running code. Note the above code was all I changed, in the auto-generated code. The auto-generated code is mainly just for styling and positioning, so don't be overwhelmed by it. You're just concerned with the code above.
MainFrame.java
MyInternalFrame.java
You'll want to just look at the code on the MyInternalFrame constructor and the actionPerformed in both class
Another Simple Fix would be just to make the
InternalFrame
an inner class of theMainFrame
so they can use the same objects that are members of theJFrame