Opening a website from within a game

Our game is complete, and we would like to start selling it. Right now, we have a “demo” and “deluxe” version that are completely separate because that’s what some game portals want. However, other game portals want to have “unlock codes”. Unlock codes would be easier for on our own website because then we would need only provide the buyer with a code instead of a separate download.

Having a link to a “buy” page isn’t a problem, but I would like for people to be able to press a button on the game menu to minimize the game and open the default web browser pointed to the buy page. I know of the System.exec methods (though I’ve never used them with complete success), but how would I use them to open up the default web browser and go to a specific url?

Maybe JDIC is an option: Communicating with Native Applications using JDIC

Definitely. I have use JDIC and it works quite well.

There is a method for applets, another for webstart and lwjgl also has a method for that.

The best option is BareBonesBrowserLaunch, just google it, it’s free source that uses System.exec(). This is my method which defaults to BareBonesBrowserLaunch if the jnlp method won’t work (becuase the jar is not launched with WebStart). 8)

Keith

public boolean openWebPage(URL url){
try {
// Lookup the javax.jnlp.BasicService object
BasicService bs = (BasicService)ServiceManager.lookup(“javax.jnlp.BasicService”);
// Invoke the showDocument method
bs.showDocument(url);
} catch(UnavailableServiceException ex) {
// Service is not supported
//ex.printStackTrace();
try {
BareBonesBrowserLaunch.openWebPage(url);
} catch(Exception ex2) {
ex2.printStackTrace();
return false;
}
}
return true;
}

I would rather avoid using a JEditorPane with JDIC to display the page. I want to use the actual default browser.

The program is an application, not an applet.

I think BareBonesBrowserLaunch sounds like the best option.

LOL. You may occasionally need to read more than two lines of a linked page :wink:

:slight_smile:

I guess I was a bit hasty. It will be much easier to use JDIC. I didn’t read quite far enough.

Though it’s a little bit of a crime to bump this topic to say something this silly, I’d like to think you all for your help. I used JDIC, and it worked as intended (well, at least once I made sure the .dll and the .jar files were in the right place and were being used).

My game is now done, and hopefully I will be able to sell it. Thank you all for the assistance you provided now and at various other times.