i making small application, jmenubar, now, got menuitem, store, opens new jframe. when click button, new jframe appears, good. but, when click close button of store jframe, don't want main jframe close. if press store-close-button now, close down both main jframe, , store jframe, on making like, 2 separate close buttons these 2 jframes? code main jframe:
public static void main(string[] args){ //create new jframe jframe frame = new jframe(); frame.settitle("mrstan"); frame.setsize(200, 200); frame.setdefaultcloseoperation( jframe.exit_on_close ); frame.setjmenubar(menubar); //set location of jframe dimension dim = toolkit.getdefaulttoolkit().getscreensize(); int screenwidth = (int) dim.getwidth(); int screenheight = (int) dim.getheight(); frame.setlocation(screenwidth / 2 - 200, screenheight / 2 - 200); //set contentpane jpanel mrstan panel = new mrstan(); frame.setcontentpane(panel); //make user not able resize frame.setresizable(false); //make jframe visible frame.setvisible(true); }
my store jframe:
public mrstanstore(){ jframe frame2 = new jframe(); frame2.settitle("store"); frame2.setsize(300, 200); frame2.setdefaultcloseoperation( jframe.exit_on_close ); //set location of jframe dimension dim = toolkit.getdefaulttoolkit().getscreensize(); int screenwidth = (int) dim.getwidth(); int screenheight = (int) dim.getheight(); frame2.setlocation(screenwidth / 2 - 200, screenheight / 2 - 200); //make user not able resize frame2.setresizable(false); //make jframe visible frame2.setvisible(true); }
don't use 2 jframes. applications should have single jframe , use jdialogs support windows. jdialogs not support exiting vm when closed not issue.
if use jframe should use dispose_on_close. when last frame closed vm exit automatically.
Comments
Post a Comment