Solved

close button in frame????

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
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.

856 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