如何将程序置于弹出窗口后面?

时间:2018-02-25 02:10:23

标签: java

正如您在我的代码中看到的那样,点击helpsection方法时,PDF文件会打开。我想知道不是PDF背后的程序,我怎么能把这个窗口带到程序前面?我尝试使用Desktop.setVisible(true);但是,我没有运气,我收到了错误消息。

enter image description here

enter image description here

计划代码

import java.util.Scanner; //taking input from user
import java.io.File;
import java.awt.Desktop;

public static void helpsection() {
        try {
            Desktop.getDesktop().open(new File("CVliamdocherty.pdf"));
            Desktop.setVisible(true);
        } catch(Exception e) {
            System.out.println(e);
        }
        System.out.println("Would you like to go back into the program to select a course to find out your grade?");
        System.out.println("You can enter 'Yes' or 'No' only.");
        outcome2 = userinput.next();
        if (outcome2.equalsIgnoreCase("Yes")) {
            step1();
        } else if (outcome2.equalsIgnoreCase("No")) {
            System.out.println((username)+" thanks for using Liam's UCAS grade calculator.");
            System.exit(0);
        } else { 
            System.out.println("You have entered an invalid value.");
            System.out.println("The program now will re run, make sure to enter the correct value next time.");
            step1();
        } 
    }

1 个答案:

答案 0 :(得分:-2)

尝试使用默认的pdf查看器

打开您的pdf doucument
Desktop desktop = Desktop.getDesktop();
desktop.open(new File("CVliamdocherty.pdf"));

我还没有尝试过您的代码,因为我目前正在使用Linux,并且需要使用xdg-open来打开默认应用程序的文档。所以,试着看看它是否有效