Java Joptionpane未与else语句一起显示
我为我的updater类编写了这段代码,但由于某些原因,它无法在底部的Java Joptionpane未与else语句一起显示,java,joptionpane,Java,Joptionpane,我为我的updater类编写了这段代码,但由于某些原因,它无法在底部的}else{语句之后到达Joptionpane: JOptionPane.showMessageDialog(空,“当前没有可用更新!!”); 相反,它只会返回输出..这很好,但我也希望它通知用户。我用格式更新了。。。 intcurrentversion=2,因此它应该运行Joptionpane public static void main(String[] args) throws IOException { Im
}else{
语句之后到达Joptionpane
:
JOptionPane.showMessageDialog(空,“当前没有可用更新!!”);
相反,它只会返回输出..这很好,但我也希望它通知用户。我用格式更新了。。。
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!!");
}
}
}
}这是您的程序,缩进已修复:
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时消息不会显示如果您修复缩进,那么缩进与代码的实际功能相匹配,那么它就会很明显。这就是为什么代码格式如此重要。不要忽视它。是的,对不起,希望这样更好!谢谢你,我把我的问题改了一点。所以intcurrentversion=2
我把它作为if(intcurrentversion>2){
所以它应该运行“JOptionPane”。@javajoejuan:他已经解释了为什么以前的版本和当前的版本没有按照您的预期工作。使用良好的缩进,然后用您的眼球告诉您其他版本应该在哪个级别。1+回答这个问题。谢谢您的回答!