0

I want to show a pop up to the user, if he wants to delete some files or not, and before the user uninstalls my application (standalone java application).

I searched for a solution, but I only found some android solutions, which are not useful for me.

I need a pure java solution or I need to know, if there is another way to do it.

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something.

JOptionPane's showConfirmDialog() asks a confirming question, like yes/no/cancel. Visit a sample tutorial here which demonstrates how it can be used.

A Sample Example :-

 // f = new File(filePath);
 // filePath is of type String and stores location of the file.
int dialogButton=JOptionPane.YES_NO_OPTION;
int dialogResult=JOptionPane.showConfirmDialog(null,"Would you like to uninstall this application(Press Yes to delete OR No to quit)???","Confirm Action", dialogButton);
        if(dialogResult==JOptionPane.YES_OPTION)
        f.delete();
        else
        {
            FinalLabel.setText("File Uninstallation process cancelled...");
            try {
                Thread.currentThread().wait(2000);
            } catch (InterruptedException ex) {
                System.exit(0);
            }
        }

So, you may try to use this in your standalone Java application.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
  • 1
    Also, let him know how to display the JOptionPane on "uninstalling" the application. – Garry Jun 16 '15 at 06:34
  • @Garry- I think SO is not a site for spoon-fed solutions. Let OP himself/herself solve this. And, OP didn't ask how should I achieve this but, still I guided him/her to a tutorial's page---you can see the link in my answer in 2nd para, – Am_I_Helpful Jun 16 '15 at 06:36
  • If he working on swing, most likely he knows about JOptionPane and your answers says about dialog box only but nothing on how to display it on uninstalling. Help wherever you can not saying with code. – Garry Jun 16 '15 at 06:40
  • @Garry-OK, I will when OP further enquires about it. BTW, I already mentioned that I've attached a link of the tutorial in my answer's 2nd paragraph. – Am_I_Helpful Jun 16 '15 at 06:42
  • @Garry-Finally, I have made the required change. If you're satisfied with the answer-please upvote... Let me know if there exists any problem. – Am_I_Helpful Jun 17 '15 at 06:31
  • Thanks, I didn't tried it and assume it may work for deleting a file from within the application but my question is same how this code will execute when you are trying to uninstall an application as per the question title? – Garry Jun 17 '15 at 09:08
  • @MrudulaP- If my answer helped, please accept the answer. See how to accept the answer ---> http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Am_I_Helpful Jun 22 '15 at 10:02
0

You may have to look for some installers and do some R&D as well on like Wix which can help you create installer for your application.

Addtionally if you to alert user on installing and uninstalling, please refer to this link Wix install/uninstall prompt and this as well Wix custom action uninstall

Community
  • 1
  • 1
Garry
  • 4,493
  • 3
  • 28
  • 48