I suggest you to use some other layout such as CardLayout to share same display space for multiple panel instead of using multiple JFrame.
See The Use of Multiple JFrames, Good/Bad Practice?
If you want to stick with current approach then create a global static reference of type JFrame to keep the reference of selected JFrame.
Use FocusListener to keep track of the selected JFarme
So, How could I recognize the last selected jframe ?
Keep the references of all opened JFrame and iterate all to check for JFrame#isFocused() or JFrame#isActive()