Solved

Close a window on button click

Posted on 2010-09-07
8
648 Views
Last Modified: 2013-12-14
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

0
Comment
Question by:sahanz
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33619712
0
 
LVL 1

Author Comment

by:sahanz
ID: 33619737
I'm talking about java, not javascript
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33619769
Sorry...lolz

Is mainwindow a frame?
have you tried this?
http://stackoverflow.com/questions/573317/java-swing-close-window-without-exiting-app
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:hazgoduk
ID: 33623104
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();

0
 
LVL 26

Expert Comment

by:ksivananth
ID: 33624771
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!
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 33634487
>> button is in the window1

Then in the code of class window1 you should have somthing like:


JButton yourButton = new JButton();
...
yourButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
          closeWindow();
      }
});

with

private void closeWindow() {
    this.dispose();
}
0
 
LVL 1

Author Closing Comment

by:sahanz
ID: 33656636
Thanks, got it worked
0
 
LVL 37

Expert Comment

by:zzynx
ID: 33669747
You're welcome.
Thanx 4 axxepting
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 51
SequenceInputStream example 3 21
Need Help! Getting a syntax error and don't understand why 3 38
running on tomcat not jboss eap 7.0 3 28
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question