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 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
#java #NetBeansIDE #programming #coding