How to Open only one JFrame form instance at a time in JAVA using NetBeansIDE



How to Open only one JFrame form instance at a time in JAVA using NetBeansIDE
Suppose I want to open JFrame2 after clicking on JFrame1 JButton
1. Open NetBeansIDE
2. Create a JFrame1 and JFrame2 forms in a project
3. Create a JButton in JFrame1
4. Add this Code for JButton Actions>ActionPerformed:
JFrame2.getObj().setVisible(true);
5. Add this code in JFrame2 class:
private static JFrame2 obj=null;
6. Change the default constructor access modifier to private
7. Make a public static method and write code below in it:
public static JFrame2 getObj(){
        if(obj==null){
            obj=new JFrame2();
        }return obj;
    }
8. Run the JFrame1 class
9. only one instance of form will be displayed at a time.
this is also called Singleton Design Pattern
10. Finish
Thank You

Like My Facebook Page for more video updates:
https://www.facebook.com/pages/Raks/335960303097841

Comments

Popular posts from this blog

How to Perform DES Encryption and Decryption of TXT file in JAVA with NetBeansIDE

How to Detect CapsLock key using Java in NetBeansIDE.

How to insert Image in MySQL Database with Java in NetBeansIDE