Does anyone know if it's possible to open a URL in a browser through Greenfoot?
/**
* Let the given URL be shown in a browser window.
*
* @param url the URL or file path to be shown.
* @return true if the web browser could be started, false otherwise.
*/
@OnThread(Tag.Swing)
public static boolean openWebBrowser(String url)
{
if (Config.isWinOS()) { // Windows
String cmd;
// catering for stupid differences in Windows shells...
if (Config.osname.startsWith("Windows 9") || Config.osname.equals("Windows Me")) // win95/98/Me
cmd = "command.com";
else
// other
cmd = "cmd.exe";
try {
// more stupid Windows differences...
if (Config.osname.startsWith("Windows 98") || Config.osname.equals("Windows Me")) {
Runtime.getRuntime().exec(new String[]{cmd, "/c", "start", '"' + url + '"'});
}
else {
Runtime.getRuntime().exec(new String[]{cmd, "/c", "start", "\"\"", '"' + url + '"'});
}
}
catch (IOException e) {
Debug.reportError("could not start web browser. exc: " + e);
return false;
}
}
else { // Mac, Unix and other
// The string should be either a URL or a file path
try {
return openWebBrowser(new URL(url));
}
catch (MalformedURLException mfue) {
return openWebBrowser(new File(url));
}
}
return true;
} try {
Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "start", "\"\"", '"' + "https://www.greenfoot.org/topics/59418/0#post_119190" + '"'});
} catch (IOException ex) {
System.out.println(ex.getMessage());
}bluej.utility.Utility.openWebBrowser("https://www.greenfoot.org/topics/59418/0#post_119190");