Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

handing window closing envent question.

Posted on 2006-04-05
4
Medium Priority
?
298 Views
Last Modified: 2010-03-31
i want before window is close by user (click on window x button), my application ask and give user a last change by show yes no dialog ,if yes do close window if no, rollback (do nothing, window still visible) i listening on windowClosing event but i don't know how to rollback, here my code


        f.addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent e) {
                                    if(showQuestionDialog("Would you like shutdown application?","Confirm message")==true){
                                        System.exit(0);                                                        
                                    }else{
                                        f.setVisible(true);                                        
                                    }
                                }
                            }
        );


f is my JFrame. whatever user choose yes or no, window still close, please help me
0
Comment
Question by:khacduyst
  • 2
  • 2
4 Comments
 

Author Comment

by:khacduyst
ID: 16388349
showQuesionDialog() function return true if yes and false for another option
0
 
LVL 92

Accepted Solution

by:
objects earned 1500 total points
ID: 16388360
set the default close operation of your fema eto do nothing

f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

do this when you create frame
0
 

Author Comment

by:khacduyst
ID: 16388369
thanks for very quick reply : )
0
 
LVL 92

Expert Comment

by:objects
ID: 16388411
no worries :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

580 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