I am coding MVC. In my controller i am listening to the action and if the user clicks a “SHOW-LIST” button i am making an instance of my view class which extends from JFrame and therein the view class i create a new JFrame. My problem is that if i click on SHOW-LIST button multiple times, i have the frame opened multiple time. Can somebody please tell me how can i do so so that once a new frame is about to open the old frame closes..
Controller
public void actionPerformed(ActionEvent event) {
String viewAction = event.getActionCommand();
...
if (viewAction.equals("SHOW-LIST")) {
showListUI = new ShowListDialogUI(displayedCustomerList);
}
}
View
class ShowListDialogUI extends JFrame{
public ShowListDialogUI (List<Customer> customerList) {
..
// I am drawing it here
..
}
}
use
CardLayout, then there no reason to playing withTop-Level Containers, put there required number ofJPanels, then just to switch betweens JPanel viewsas
@trashgodnotified, really not good idea, wayotherwise have to clean-up (remove all contents) uselless container, because Top-Level Containers never will be GC’ed