Solved

close button in frame????

Posted on 2002-06-27
5
284 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
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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now