java - Program Terminates without running in eclipse -


when run code ( having simple buttons , login button action listener), terminates without running , without showing screen.

i have tried system.exit(0); in main function overcome terminating issue in vain

   public class home extends jframe{  dimension screensize = toolkit.getdefaulttoolkit().getscreensize(); int width = (int) screensize.getwidth(); int height = (int) screensize.getheight(); color cardinal = new color(194, 35, 38); int w=155; int h=50; public home(string title) {      super(title);      getcontentpane().setsize(width,height);     getcontentpane().setbackground(color.white);     getcontentpane().setlayout(null);       final jpanel panel2 = new jpanel();     panel2.setbounds(364, 33, 664, 344);     getcontentpane().add(panel2);      jpanel panel3 = new jpanel();     panel3.setbackground(color.white);     panel3.setbounds(81, 382, 947, 243);     getcontentpane().add(panel3);     panel3.setlayout(null);      jbutton btnhome = new jbutton("home");     btnhome.setfont(new font("times new roman", font.plain, 20));     btnhome.setforeground(color.white);     btnhome.setbackground(cardinal);     btnhome.setbounds(517, 33, w, h);     btnhome.setcontentareafilled(false);     btnhome.setopaque(true);     panel3.add(btnhome);      jbutton btnclients = new jbutton("clients");     btnclients.setfont(new font("times new roman", font.plain, 20));     btnclients.setforeground(color.white);     btnclients.setbounds(690, 33, w, h);     btnclients.setbackground(cardinal);     btnclients.setcontentareafilled(false);     btnclients.setopaque(true);     panel3.add(btnclients);      jbutton btnclose = new jbutton("close");     btnclose.setfont(new font("times new roman", font.plain, 20));     btnclose.setforeground(color.white);     btnclose.setbounds(690, 198, w, h);     btnclose.setbackground(cardinal);     btnclose.setcontentareafilled(false);     btnclose.setopaque(true);     panel3.add(btnclose);      jbutton btnlogin = new jbutton("admin login");     btnlogin.addactionlistener(new actionlistener() {         public void actionperformed(actionevent arg0) {             login l=new login();             panel2.add(l);         }     });     btnlogin.setfont(new font("times new roman", font.plain, 20));     btnlogin.setforeground(color.white);     btnlogin.setbounds(517, 116, w, h);     btnlogin.setbackground(cardinal);     btnlogin.setcontentareafilled(false);     btnlogin.setopaque(true);     panel3.add(btnlogin);      jpanel panel1 = new jpanel();     panel1.setborder(new etchedborder(etchedborder.lowered, new color(204,       51, 0), null));     panel1.setbackground(color.white);     panel1.setbounds(81, 33, 263, 344);     getcontentpane().add(panel1);     panel1.setlayout(null);       jbutton btnstartmonitoring = new jbutton("");     btnstartmonitoring.seticon(new imageicon(path1));     btnstartmonitoring.setbackground(cardinal);      btnstartmonitoring.setforeground(color.white);     btnstartmonitoring.setfont(new font("tahoma", font.plain, 15));     btnstartmonitoring.setbounds(10, 274, 239, 59);      panel1.add(btnstartmonitoring);      jlabel lbllogo = new jlabel("new label");     lbllogo.seticon(new imageicon(path2));     lbllogo.setbounds(0, 11, 263, 253);     panel1.add(lbllogo);  }   public static void main(string args[]) {        new home("home");         //system.exit(0); } 

}

edited

i have login class extended jpanel. when click on login button home. not showing login panel login.class

   public class login extends jpanel {    private jtextfield txtpassword;    private jtextfield txtid;    color cardinal = new color(194, 35, 38);    int w=155;    int h=50;    public login() {     setbackground(color.white); setlayout(null);  jlabel lbllogin = new jlabel("login   "); lbllogin.setbackground(color.orange); lbllogin.sethorizontalalignment(swingconstants.right); lbllogin.setfont(new font("trajan pro", font.bold, 36)); lbllogin.setbounds(125, 0, 424, 59); lbllogin.setbackground(cardinal); //lbllogin.setcontentareafilled(false); lbllogin.setopaque(true); lbllogin.setforeground(color.white); add(lbllogin);  jlabel lblid = new jlabel("id"); lblid.sethorizontalalignment(swingconstants.right); lblid.setfont(new font("tekton pro", font.plain, 23)); lblid.setbounds(181, 127, 66, 28); add(lblid);  jlabel lblpassword = new jlabel("password"); lblpassword.sethorizontalalignment(swingconstants.right); lblpassword.setfont(new font("tekton pro", font.plain, 23)); lblpassword.setbounds(136, 188, 111, 28); add(lblpassword);  txtpassword = new jtextfield(); lblpassword.setlabelfor(txtpassword); txtpassword.setbounds(266, 183, 256, 41); lblpassword.setforeground(cardinal); add(txtpassword); txtpassword.setcolumns(10);  txtid = new jtextfield(); lblid.setlabelfor(txtid); txtid.setbounds(266, 123, 256, 39); lblid.setforeground(cardinal); add(txtid); txtid.setcolumns(10);  jbutton btnlogin = new jbutton("login"); btnlogin.setforeground(color.white); btnlogin.setfont(new font("times new roman", font.plain, 20)); btnlogin.setbounds(324, 294, w, h); btnlogin.setbackground(cardinal); btnlogin.setcontentareafilled(false); btnlogin.setopaque(true); add(btnlogin); setvisible(true); 

}

answer second part:

  1. import mouselistener, import java.awt.event.mouselistener;

  2. construct mouselistener somewhere, include action of button

  3. where define btnlogin, add line btnlogin.addmouselistener(<name of mouselistener>);

an example: http://www.java2s.com/code/java/swing-jfc/buttonactionsample.htm


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -