我写了这个代码为我的更新类展示,但由于某种原因,它不会得到在Joptionpane
的}else{
语句后在底部:Java的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!!");
}
}
}
}
如果您修复缩进,所以缩进ma看看代码实际上做了什么,那么它将是显而易见的。 – immibis
这就是为什么代码格式化非常重要。不要忽视它。 –
是的,抱歉,希望这是更好的! – javajoejuan