1

I am creating a game and I made a Launcher. I have seen on other games made out of Java (Like MineCraft) have a webpage on the launcher. I was woundering how to put a webpage on a Java Swing GUI panel. I would also like to know how to open their browser up to a link with a button. Thanks,

Blockquote

Oak
  • 498
  • 1
  • 5
  • 19
  • Maybe this help you: http://stackoverflow.com/questions/2020854/embed-firefox-browser-in-java-swing and this: http://stackoverflow.com/questions/10601676/display-a-webpage-inside-a-swing-application (seems that it is a duplicate of this one) – porfiriopartida Sep 23 '13 at 22:48

2 Answers2

3

To open a url in the system's web browser you can use java.awt.Desktop.browse(URI). This allows you to keep your Java code platform independent, and even allows you to check to see if an operation is supported before trying to use it.

To load a web page within Java, I've had some success using the JavaFX WebView.

ggovan
  • 1,907
  • 18
  • 21
  • ggovan's answer is correct, even for opening a web page in a Swing Panel, as you can place the `WebView` in a [JFXPanel](http://docs.oracle.com/javafx/2/api/javafx/embed/swing/JFXPanel.html). See Oracle's tutorial: [SimpleSwingBrowser](http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm). – jewelsea Sep 24 '13 at 02:47
1
import java.awt.Desktop;
import java.net.URI;

class URLBrowsing 
{

    public static void main(String args[]) 
    {

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

            // Browse a URL, for example www.facebook.com
            d.browse(new URI("http://www.facebook.com")); 
            // This open facebook.com in your default browser.
        }
        catch(Exception ex) 
        {
            ex.printStackTrace();
        }
    }
}
kai
  • 6,702
  • 22
  • 38
Nandom Gusen
  • 51
  • 1
  • 5