Link to home
Start Free TrialLog in
Avatar of sahanz
sahanz

asked on

Close a window on button click

This code is wrote for click event.When click the button main window appeared.but window 1 is not closed.button is in the window1.I want to
close the window 1 when click the button..
if(no==25){
                JOptionPane.showMessageDialog(null,"Number correct");
		mainwindow mw=new mainwindow();
		mw.show();
		window1 w1=new window1();
		w1.dispose();
		}

Open in new window

Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Avatar of sahanz
sahanz

ASKER

I'm talking about java, not javascript
You're creating a new frame then closing it which doesn't seem right. If your button is in the frame you want to close why are you creating a new one? You want to just do

dispose();

if you want to close the existing window, you shouldn't create a new instance instead should call the dispose method in the existing instance!
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sahanz

ASKER

Thanks, got it worked
You're welcome.
Thanx 4 axxepting