Solved

close button in frame????

Posted on 2002-06-27
5
283 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
Comment Utility
Add a window listener to the frame, and prompt the user in the windowClosing() method.
0
 

Accepted Solution

by:
udaykumar22 earned 50 total points
Comment Utility
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
Comment Utility
Thanks for elaborating on my original comment :)
0
 
LVL 5

Expert Comment

by:vemul
Comment Utility
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
Comment Utility
Objects, Look for your question in this topic area

Computer101
E-E Admin
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

771 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

14 Experts available now in Live!

Get 1:1 Help Now