java程序中的internet更新检查
我的程序有一个更新检查,更新链接到,当我运行应用程序时,它会说我的程序过时了(如果您当前的启动程序版本与联机版本有任何不同,则默认消息。但我测试了它,以打印我的当前版本和最新版本,它们是相同的。以下是我的代码:java程序中的internet更新检查,java,java.util.scanner,updatecheck,Java,Java.util.scanner,Updatecheck,我的程序有一个更新检查,更新链接到,当我运行应用程序时,它会说我的程序过时了(如果您当前的启动程序版本与联机版本有任何不同,则默认消息。但我测试了它,以打印我的当前版本和最新版本,它们是相同的。以下是我的代码: package net.ogpc.updates; import java.awt.BorderLayout; import java.awt.Desktop; import java.io.IOException; import java.net.URI; import java.ne
package net.ogpc.updates;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Scanner;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import net.ogpc.GUI.Launcher;
public class UpdatesCheck {
JFrame frame = new JFrame("Checking For Updates...");
JLabel lb = new JLabel("Checking For Updates...");
String build = Launcher.build;
public UpdatesCheck() {
frame.setSize(160, 50);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
frame.add(lb, BorderLayout.NORTH);
updateCheck();
frame.setVisible(true);
}
@SuppressWarnings("resource")
public void updateCheck() {
try {
URL url = new URL("http://pastebin.com/raw.php?i=mWNT0sZa");
Scanner s = new Scanner(url.openStream());
String vs = s.nextLine();
if (vs != build) { //there is an update!
System.out.println("update found");
int ans = JOptionPane.showConfirmDialog(null, "You seem to be using an outdated Launcher.. \nCurrent Version: " + vs + " - Newest Version: " + Launcher.build + "\nDo you want to update the launcher?", "UPDATE FOUND!", JOptionPane.YES_NO_OPTION);
if (ans == JOptionPane.YES_OPTION) {
//go to update page
try {
openWebpage(url.toURI()); //open update page from website
} catch (URISyntaxException e) {
e.printStackTrace();
}
System.exit(0);
} else if (ans == JOptionPane.NO_OPTION) {
//end application
JOptionPane.showMessageDialog(null, "You canceled the update!\nYou must have the most up to date verion of the launcher to run.", "You need to update!", JOptionPane.NO_OPTION);
System.exit(0);
}
}else if (vs == build){ //no update found
frame.setVisible(false);
Launcher.frame.setEnabled(true);
Launcher.frame.setVisible(true);
}
}
catch(IOException ex) {
ex.printStackTrace();
}
}
public static void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(new URL("http://hahn2014.weebly.com/ogpc-2014-update.html").toURI());
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new UpdatesCheck();
}
}
任何帮助都将不胜感激!试试看
if ( ! build.equals(vs) ) { //there is an update!
不要反过来做,
vs
可能是空的。build
不会,因为我假设它是一个文本。首先,比较字符串是否与相等,而不是=
和!=