So I have a code which is like:
Class A
Class B
methodB(frame initialization)
Class C
methodC(frame initialization)
An object of ClassA calls ClassB and then a frame is initialized. Now when a button on ClassB is pressed an object of ClassC is initialized.
When a button on ClassC is pressed I need to reinitialize an object of ClassA with updated parameters. So while reinitializing an object of ClassA from ClassC, the older object of ClassC is still there.
How do I exit from the old object of ClassA and initialize a new object of ClassA when a particular button is pressed? I am able to create a new instance of ClassA but the problem is in exiting from the previous object from ClassC because if I add System.exit(0)
in classC, it closes both objects of ClassA. I just want the old object to close.
Edit: You can't do this. You can't reinitialize this
or overwrite an instance globally by reconstructing it.
You need to keep a reference to the existing class A instance. When creating an instance of class B, make it accept class A in the constructor and pass this
. The same when creating class C. Now if you have proper getters, you can, in C, call this.getB().getA().performSomeUpdate()
whre performSomeUpdate
updates the A instance to new parameters by setting fields.