To properly destroy a JFrame
, you should dispose it.
previousTraffic.dispose();
TrafficMainGUI traffic=new TrafficMainGUI(storeValue);
traffic.setVisible(true);
From the documentation :
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
Your question is quite vague about what you are doing with the threads.
As mentioned by @MadProgrammer, when you are working with swing
, you should take into account the EDT. But to get a more specific help, you should provide an sscce.