swing - Closing java popup frame without exiting program -
public buttongrid(int width, int length){ //constructor frame.settitle("mpc"); frame.setlayout(new gridlayout(width,length)); //set layout grid=new jbutton[width-1][length]; //allocate size of grid for(int y=0; y<length; y++){ for(int x=0; x<width-1; x++){ grid[x][y]=new jbutton("("+x+","+y+")"); //creates new button frame.add(grid[x][y]); //adds button grid grid[x][y].addactionlistener(this); grid[x][y].addkeylistener(this); //grid[x][y].setmnemonic(keyevent.vk_0); grid[x][y].setpreferredsize(new dimension(75,75)); } } for(int =0; i<boxlist.length; i++) box.additem(boxlist[i]); box.addactionlistener(this); frame.add(box); frame.add(met_speed); frame.add(play); play.addactionlistener(this); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.pack(); //sets appropriate size frame frame.setvisible(true); //makes frame visible } public void newwindow(){ jframe frame1 = new jframe(); frame1.setlayout(new gridbaglayout()); gridbagconstraints gbc = new gridbagconstraints(); jtextfield[] btn = new jtextfield[12]; jlabel[] lbl = new jlabel[12]; jlabel name = new jlabel("preset name"); jtextfield name1 = new jtextfield(); name1.setpreferredsize(new dimension(100,25)); gbc.gridx = 0; gbc.gridy = 0; frame1.add(name, gbc); gbc.gridx++; frame1.add(name1, gbc); gbc.gridx = 0; gbc.gridy = 1; for(int = 0; i<12; i++){ lbl[i] = new jlabel("button" + (i+1)); frame1.add(lbl[i], gbc); gbc.gridy++; } gbc.gridx = 1; gbc.gridy = 1; for(int = 0; i<12; i++){ btn[i] = new jtextfield(); btn[i].setpreferredsize(new dimension(75,25)); frame1.add(btn[i], gbc); gbc.gridy++; } gbc.gridx = 0; gbc.gridy = 14; jbutton save = new jbutton("save"); frame1.add(save, gbc); frame1.setdefaultcloseoperation(jframe.exit_on_close); frame1.pack(); //sets appropriate size frame frame1.setvisible(true); //makes frame visible }
the first function buttongrid called in main , contains real program. after button pressed, newwindow() called popup. point, works fine, when close frame1, closes frame , ends program.
am doing correctly or there need add?
you may try this:
frame1.setdefaultcloseoperation(jframe.dispose_on_close);//<-- destroy frame
Comments
Post a Comment