Add a component listener to the second frame, and when the frame is being shown dispose the first frame.