Solved

Close a window on button click

Posted on 2010-09-07
8
649 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

734 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