0

I've made a Notepad program and i wonder how can i create a popup window which pops up when i click on the "close" button and ask the user if he would like to save the content which was written in the note pad.

I was think of JOptionPane as a solution but not sure how to add buttons to the window it creates and how to call the "popup" window.

Here's how i expect my popup window to look like:

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
gil
  • 2,388
  • 1
  • 21
  • 29

2 Answers2

0

write the code for showing JOptionPane object within the windowClosing(WindowEvent e){} method of the WindowListener interface by implementing the interface with the application's main class.

Visit this link for more information: Java windows listener interface methods

0

This is the code to "listen" when the user closes the window (Clicks "X") :

yourJFrame.addWindowListener(new WindowAdapter() {     
        public void windowClosing(WindowEvent e) {

                //your code , you can create the JOptionPane here.

        }
 });
Mayuso
  • 1,291
  • 4
  • 19
  • 41