1

I am wondering how I can make my Java game automatically check for updates when a button is pressed, I have an ActionListener calling my UpdateGUI class:

btnUpdate.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        new UpdateGUI();
    }
});

and then I am stuck from here on, I've got the GUI sorted (labels, buttons etc), but it's just the update checker, I also would like help to make a label appear when an update is available.

I have tried looking through the various questions provided to me as I was making this question, all of which did not help me.

UpdateGUI Code

public class UpdateGUI {

    public UpdateGUI() {
        JFrame starGameUpdater = new JFrame();
        starGameUpdater.setTitle("StarGame Updater");
        starGameUpdater.getContentPane().setLayout(null);

        JLabel labelStargameUpdate = new JLabel("StarGame Updater");
        labelStargameUpdate.setHorizontalAlignment(SwingConstants.CENTER);
        labelStargameUpdate.setBounds(165, 11, 94, 14);
        starGameUpdater.getContentPane().add(labelStargameUpdate);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Connor Wright
  • 110
  • 1
  • 13
  • 2
    What kind of update? New data, new Java version or new application version? You'll may need a component that can send an HTTP-Request to the corresponding server that will deliver newest version number. – Tom Oct 21 '14 at 18:43
  • When I release a new version of my game onto my FTP server – Connor Wright Oct 21 '14 at 18:43
  • Please check this question, it might help you: http://stackoverflow.com/questions/14617/java-what-is-the-best-way-to-sftp-a-file-from-a-server. – Tom Oct 21 '14 at 18:49
  • That sort of helped me, I need to check for a newly modified version of the game, and then download it and replace the .jar file it (downloads from the launcher and executed the new .jar file) – Connor Wright Oct 21 '14 at 18:56
  • or, exit after it installs the new update and drops the file i... say like folder in %appdata% (in StarGame folder (name of my game)) or Desktop in a new folder – Connor Wright Oct 21 '14 at 18:57
  • Do you have any idea how I can go about doing this @Tom – Connor Wright Oct 21 '14 at 19:12
  • No, but I guess there are a lot of questions/tutorials available on how to request files from an ftp server. – Tom Oct 21 '14 at 19:21
  • 1
    Use [tag:java-web-start]. – trashgod Oct 21 '14 at 20:24
  • Me personally I would copy how it is done for Minecraft: using an external launcher application which can update and manage the game rather than a Java program which updates itself. Check for update, download, start new Java process (using Process class) to actually boot the game. That also gives you the flexibility to provide startup parameters to the forked process. – Gimby Oct 21 '14 at 20:35
  • @Gimby and how would I go about doing that? – Connor Wright Oct 23 '14 at 15:25
  • I've just looked through the whole minecraft code, I cannot find anything to do with updating – Connor Wright Oct 24 '14 at 15:55

1 Answers1

2

Java Web Start provides auto-updates. The JNLP API available to JWS apps. also allows the app. to take programmatic control of updates through the DownloadService.

DownloadService service allows an application to control how its own resources are cached, to determine which of its resources are currently cached, to force resources to be cached, and to remove resources from the cache. The JNLP Client is responsible for providing a specific implementation of this service.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433