How to disable main JFrame when open new JFrame

后端 未结 5 1509
旧时难觅i
旧时难觅i 2020-12-03 14:28

Example now I have a main frame contains jtable display all the customer information, and there was a create button to open up a new JFrame that allow user to create new cus

5条回答
  •  醉梦人生
    2020-12-03 15:04

    Sorry for the late answer but have you considered the Singleton design pattern? It will return the same instance of a class whenever you want the class. So if the user wants a frame to enter the details, there will only be one frame open (same instance)

    It goes something like this:

    private static MySingleFrame instance = null; //global var
    
    private MySingleFrame() { } //private constructor 
    private static MySingleFrame getInstance()
    {
    
    if(instance == null)
    {
    instance = new MySingleFrame();
    }
    
    //returns the same instance everytime MySingleFrame.getInstance() is called
    return instance; 
    
    
    }
    

提交回复
热议问题