-1

I am new to Java Development, i have a Jframe1 which opens a new window Jframe2 with the object passing inside the constructor like this,

final EmployeeLookUp f = new EmployeeLookUp(this);

And the Jframe2 constructor looks like,

 public EmployeeLookUp(LibraryHR lhr1) {
        initComponents();
        lhr = lhr1;
    }

Am making some changes inside the object lhr and i want to pass the modified object back to the Main frame On clicking the ok button. How can i do that?

final EmployeeLookUp f = new EmployeeLookUp(this);
f.show();
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        f.addWindowListener( new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent we) {
                //i want to get the object from Jframe2 to here
            }
        } );

EDIT:

My question is how to pass the object in Frame2 to Frame1 in closing event of Frame2?

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • 2
    both the reference `lhr1` and `lhr` will point to same object so any changes made by one reference will change the object. No need to pass the modified object. – Braj Jun 04 '14 at 07:59
  • @Braj I think i have not made the question clear, its not about the object, i want to get the object in the closing event on the main frame. – Sajeetharan Jun 04 '14 at 08:50
  • 1
    Share the relevant code to make it clear. – Braj Jun 04 '14 at 08:52

1 Answers1

1

It's worth reading Is Java “pass-by-reference” or “pass-by-value”?.

Both the reference lhr1 and lhr will point to same object in the memory so any changes made by one reference will change the original object.

Understand it visually.

enter image description here

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76