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
Watch video How to Open only one JFrame form instance at a time in JAVA using NetBeansIDE online without registration, duration hours minute second in high quality. This video was added by user raksrahul 25 May 2013, don't forget to share it with your friends and acquaintances, it has been viewed on our site 10,361 once and liked it 64 people.