This site requires JavaScript, please enable it in your browser!
Greenfoot back
sjoerdieman
sjoerdieman wrote ...

2015/1/19

Open the webbrowser

sjoerdieman sjoerdieman

2015/1/19

#
How can i use this code:
import java.awt.Desktop;
import java.net.URI;
public void main(String args[]) throws Exception
    {

        // Create Desktop object
        Desktop d=Desktop.getDesktop();

        // Browse a URL, say google.com
        d.browse(new URI("http://google.com"));

    }
in a if statement like this:
private void hover()
    {
        MainMenu world = (MainMenu) getWorld();
        if(Greenfoot.mousePressed(this) && isInMainMenu == true)
        {
            this.setImage("MainMenuWebsite.png");
        } else if(Greenfoot.mouseClicked(this) && isInMainMenu == true)
        {
            this.setImage("MainMenuWebsiteS.png");
************** I want to open the browser at this location **************
        }
    } 
danpost danpost

2015/1/19

#
You need to catch any exceptions:
Desktop d=Desktop.getDesktop();
try
{
   d.browse(new URI("http://google.com"));
}
catch (Exception e)
{
    /** any processes you want to do when an exception is thrown */
}
sjoerdieman sjoerdieman

2015/1/19

#
Thanks got it!
You need to login to post a reply.