问题
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