How to allow JOptionPanes to show in a Windows Service

半腔热情 提交于 2020-01-14 05:48:05

问题


The program I created deletes all files in a folder then displays a JOptionPane. It runs fine as a jar file but not when I create a service out of it. When I run the service it deletes the files but does not display the JOptionPane.

I've already tried the: "Allow service to interact with desktop"

    package testPackage;

    import java.io.File;

    import javax.swing.JDialog;
    import javax.swing.JOptionPane;


    public class TestPack{
        private static void deleteAll(File del) {
            if (!(del.isDirectory())) {
                del.delete();
            } else {
                File[] filelist = del.listFiles();
                if (filelist != null) {
                    for (File files : filelist) {
                        deleteAll(files);
                        files.delete();
                    }
                }
            }
        }
        public static void main(String[] args) {
            File test = new File("<Path to folder to delete files>");
            deleteAll(test);
        final JDialog dialog = new JDialog();
        dialog.setAlwaysOnTop(true);
        int buttons = JOptionPane.YES_NO_OPTION;
        while(buttons == 0) {
        buttons = JOptionPane.showConfirmDialog(dialog, "Have the files been deleted", "Test", buttons);
        }
    }
}

来源:https://stackoverflow.com/questions/57296949/how-to-allow-joptionpanes-to-show-in-a-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!