java - JFrame Not Disposing -


i attempting dispose jframe on button click. however, when click button executes except jframe doesn't close! why this? problem jframe opening directly after it?

public static void login() {     jframe loginframe = new jframe();     jpanel loginpanel = new jpanel();     jbutton loginbutton = new jbutton("login");     jlabel usernametext = new jlabel("username:");     jlabel passwordtext = new jlabel("password:");     final jtextfield usernamefield = new jtextfield(15);     final jtextfield passwordfield = new jtextfield(15);     status.setforeground(color.red);      new loginbackground();      loginpanel.add(usernametext);     loginpanel.add(usernamefield);     loginpanel.add(passwordtext);     loginpanel.add(passwordfield);     loginpanel.add(loginbutton, borderlayout.center);     loginpanel.add(status);     loginframe.add(loginpanel);      loginpanel.add(loginbackgroundlabel);     loginframe.add(loginpanel);      loginframe.repaint();     loginframe.setvisible(true);     loginframe.setsize(1200, 800);      loginpanel.setlayout(null);      usernametext.setsize(100, 100);     passwordtext.setsize(100, 100);      usernametext.setfont(new font("serif", font.plain, 20));     usernametext.setforeground(color.white);      passwordtext.setfont(new font("serif", font.plain, 20));     passwordtext.setforeground(color.white);      loginbackgroundlabel.setlocation(0, 0);     usernametext.setlocation(555, 230);     passwordtext.setlocation(555, 290);     usernamefield.setlocation(500, 300);     passwordfield.setlocation(500, 350);     loginbutton.setlocation(550, 400);     status.setlocation(500, 450);      loginpanel.revalidate();     loginframe.repaint();      try {         thread.sleep(1000);     } catch (interruptedexception e2) {         e2.printstacktrace();     }      new sound();      login = false;      loginbutton.addactionlistener(new actionlistener() {         public void actionperformed(actionevent e) {             try {                 frame.loginframe.setvisible(false);                 frame.loginframe.dispose();                 username = usernamefield.gettext();                 password = passwordfield.gettext();                 connect.checklogin();                 sound.clip.stop();             } catch (sqlexception e1) {                 e1.printstacktrace();             }         }     }); } 

set window action on close, dispose on close.

setdefaultcloseoperation( windowconstants.dispose_on_close ); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -