java - JFrame-JDialog comunication -


i have jframe main window wich has register button on in.click register button , jdialog windows pops out.

public void mouseclicked(mouseevent e) {                 reg new1=new reg(users);                 new1.setvisible(true);             } 

the jdialog window has 2 buttons->register,cancel.both of them must , close dialog window.

this tried. in reg(dialog window)---> btncancel:

public void mouseclicked(mouseevent e) {                         dialog.dispose();                         system.out.println("reg disposed cancel button");                     } 

this closes d window when run d window guess when executed main window(button clicked) still exists object in main fraim"class" , doesn't close.what should ?how make close ?

you need way frame determine how dialog closed

// why using `mouselistener` on buttons?? // user use keyboards to, use actionlistener instead public void mouseclicked(mouseevent e) {     reg new1=new reg(users);     new1.setvisible(true);     switch (new1.getdisposestate()) {         case reg.ok:             // clicked ok             break;         case reg.cancel:             // clicked cancel or closed press [x]             break;     } } 

then in reg class, need maintain information state...

public class reg extends jdialog {     public static final int ok = 0;     public static final int cancel = 1;      private int disposestate = cancel;      //...      public int getdisposestate() {         return disposestate     }      public void setdisposestate(int state) {         disposestate = state;     } 

then change state

// why using `mouselistener` on buttons?? // user use keyboards to, use actionlistener instead public void mouseclicked(mouseevent e) {     setdisposestate(cancel);     dialog.dispose();     system.out.println("reg disposed cancel button"); } 

this assumes dialog modal of course...

now, having said that, personally, make reg class jpanel , add joptionpane instead or use cardlayout

take at:

...for more details


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -