java - i want to hide the first frame when the new frame window appear -
i want hide previous window frame when new window appear after pressing submit button,how hide previous window or close without pressing cross button
enter code here public static void main(string[] args) { jframe frame = new jframe("project format creator"); jbutton btn5 = new jbutton("submit"); jpanel panel = new jpanel(new gridbaglayout()); gridbagconstraints cst = new gridbagconstraints(); cst.fill = gridbagconstraints.horizontal; cst.gridx = 0; cst.gridwidth = 1; cst.weightx = 0.1; cst.gridy = 8; //third row panel.add(btn5,cst); btn5.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { jframe frame1 = new jframe("project format creator"); frame1.setdefaultcloseoperation(jframe.exit_on_close); frame1.setsize(300,300);//int width int height frame1.getcontentpane().add(panel); frame1.setvisible(true); } }); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setsize(300,300);//int width int height frame.getcontentpane().add(panel); frame.setvisible(true); }
use frame.setvisible(false);
if you're going show jframe again, or frame.dispose();
if you're done it.
public void actionperformed(actionevent e) { frame.dispose(); // dispose old frame jframe frame1 = new jframe("project format creator"); frame1.setdefaultcloseoperation(jframe.exit_on_close); frame1.setsize(300,300);//int width int height frame1.getcontentpane().add(panel); frame1.setvisible(true); }