?
Solved

close button in frame????

Posted on 2002-06-27
5
Medium Priority
?
293 Views
Last Modified: 2013-11-23
Hi guys. How would i trap in frame so that when a user click the X button(AWT Frame), i will issue a message asking "Do u really want to exit?"..

thanks..
0
Comment
Question by:rdy1437
[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
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7115548
Add a window listener to the frame, and prompt the user in the windowClosing() method.
0
 

Accepted Solution

by:
udaykumar22 earned 200 total points
ID: 7115899
hi,

Try this...it works...

===========================================================

JFrame JF = new JFrame("My Frame");

JPanel JPParent = new JPanel();

JF.getContentPane().add(JPParent, null);

JF.addWindowListener
(
 new java.awt.event.WindowAdapter()
 {
  public void windowClosing(WindowEvent WE)
  {
   int ChosenOption = JOptionPane.showConfirmDialog
(
 JPParent,
 "Do you really want to exit?",
 "Exit Screen",  
 JOptionPane.OK_CANCEL_OPTION
);

   if(ChosenOption == JOptionPane.CANCEL_OPTION)
   {
// Do nothing is user presses 'Cancel'
    return;
   }
   else
   {
// Do whatever operation when you want is user presses 'Ok'...in this case --- Exits the application
    System.exit(0);
   }
  }
 }
);

===========================================================

Regards,
Uday.
0
 
LVL 92

Expert Comment

by:objects
ID: 7117563
Thanks for elaborating on my original comment :)
0
 
LVL 5

Expert Comment

by:vemul
ID: 7887963
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- split points between objects and udaykumar22

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7959696
Objects, Look for your question in this topic area

Computer101
E-E Admin
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

770 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