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
  • 56,735
  • 45
  • 213
  • 327
gil
  • 1,945
  • 1
  • 14
  • 27

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,253
  • 3
  • 19
  • 40