Java Joptionpane没有显示else语句

时间:2016-07-26 01:16:53

标签: java joptionpane

我为updater类编写了这段代码,但由于某些原因,它在底部Joptionpane语句之后无法访问}else{

JOptionPane.showMessageDialog(null,"Currently no updates available!!");

相反,它只是return ...这很好,但我也希望通知用户。我更新了格式化...... intcurrentversion = 2,所以它应该运行Joptionpane

public static void main(String[] args) throws IOException {
    ImageIcon updateicon = new ImageIcon("resources/update.png");
    String url = "http://example.com/wp-content/uploads/version/Version.html";
    Document document = Jsoup.connect(url).get();
    String getcurrentversion = document.select("version").first().text();  
    int intcurrentversion = Integer.parseInt(getcurrentversion);    
    System.out.println(intcurrentversion);

    if (intcurrentversion > 2) {

        int response = JOptionPane.showConfirmDialog(null, "Would you like to update?", "Update available!",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,updateicon);

        if (response == JOptionPane.NO_OPTION) {
            System.out.println("No button clicked");
        } else if (response == JOptionPane.YES_OPTION) {
            System.out.println("Yes button clicked");

            {
                String filePath = "C:/Windows/Updater.exe";//
                try {
                    Process p = Runtime.getRuntime().exec(filePath);

                } catch (Exception g) {
                    g.printStackTrace();
                }
            }


        } else {
            JOptionPane.showMessageDialog(null,"Currently no updates available!!");

        }
    }
}

}

1 个答案:

答案 0 :(得分:2)

这是修复了缩进的程序:

import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class CheckForUpdate {

    public static void main(String[] args) throws IOException {
        ImageIcon updateicon = new ImageIcon("resources/update.png");
        String url = "http://example.com/wp-content/uploads/version/Version.html";
        Document document = Jsoup.connect(url).get();
        String getcurrentversion = document.select("version").first().text();  
        int intcurrentversion = Integer.parseInt(getcurrentversion);    
        System.out.println(intcurrentversion);

        if (intcurrentversion > 0) {

            int response = JOptionPane.showConfirmDialog(null, "Would you like to update?", "Update available!",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,updateicon);

            if (response == JOptionPane.NO_OPTION) {
                System.out.println("No button clicked");
            } else if (response == JOptionPane.YES_OPTION) {
                System.out.println("Yes button clicked");

                {
                    String filePath = "C:/Windows/Updater.exe";//
                    try {
                        Process p = Runtime.getRuntime().exec(filePath);

                    } catch (Exception g) {
                        g.printStackTrace();
                    }
                }


            } else {
                JOptionPane.showMessageDialog(null,"Currently no updates available!!");

            }
        }
    }
}

我希望现在很明显为什么在intcurrentversion< = 0时没有显示消息。