java - call constructor that calls private initialization of components -


i discovered netbeans had built in swing tools , im playing around ran trouble. how call initialization main method. because without main method program wont execute, cant call constructor, or cannot call initcomponents() because private. how working??

public static void main(string [] args){   } /**  * creates new form password  */ public password() {     initcomponents(); }  /**  * method called within constructor initialize form.  * warning: not modify code. content of method  * regenerated form editor.  */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code">                           private void initcomponents() {      jpanel1 = new javax.swing.jpanel();     jlabel1 = new javax.swing.jlabel();     jtextfield1 = new javax.swing.jtextfield();     jlabel2 = new javax.swing.jlabel(); ... 

as @madprogrammer has mentioned, have create instance of class, calling constructor, this:

import java.awt.borderlayout; import java.awt.eventqueue; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jtextarea;  @suppresswarnings("serial") public class class extends jframe {     private jbutton btn;     private jtextarea txtarea;      public static void main(string[] a)     {         eventqueue.invokelater(new runnable() {             public void run()             {                 new class();// creating instance of class             }         });     }      public class()     {         super("title");          initialize();          setdefaultcloseoperation(jframe.exit_on_close);         setvisible(true);         pack();         setlocationrelativeto(null);     }      private void initialize()     {         btn = new jbutton("click me");         txtarea = new jtextarea();          add(btn, borderlayout.north);         add(txtarea, borderlayout.center);     } } 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -