我想向用户显示一个弹出窗口,如果他想要删除某些文件,并且在用户卸载我的应用程序(独立的Java应用程序)之前。
我搜索了一个解决方案,但我只找到了一些对我没用的Android解决方案。
我需要一个纯粹的java解决方案,或者我需要知道,如果还有其他方法可以做到这一点。
答案 0 :(得分:0)
JOptionPane可以轻松弹出提示的标准对话框 用户获取价值或通知他们。
JOptionPane的showConfirmDialog()会询问确认问题,例如是/否/取消。 Visit a sample tutorial here演示如何使用它。
示例示例: -
// 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);
}
}
因此,您可以尝试在独立的Java应用程序中使用它。
答案 1 :(得分:0)
您可能需要寻找一些安装程序并执行一些R& D,例如Wix,这可以帮助您为应用程序创建安装程序。
另外,如果您要提醒用户安装和卸载,请参阅此链接Wix install/uninstall prompt以及此Wix custom action uninstall