我寫了這個代碼爲我的更新類展示,但由於某種原因,它不會得到在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