How do you open web pages in Java?

后端 未结 6 1481
庸人自扰
庸人自扰 2021-02-13 04:19

Is there a simple way to open a web page within a GUI\'s JPanel?

If not, how do you open a web page with the computer\'s default web browser?

I am hoping for so

6条回答
  •  遥遥无期
    2021-02-13 05:06

    Please try below code :

    import java.awt.Desktop;
    import java.net.URI;
    import java.net.URISyntaxExaception;
    
    //below is the code
    //whatvever the url is it has to have https://
    
    Desktop d = Desktop.getDesktop();
    try {
        d.browse(new URI("http://google.com"));
    } catch (IOException | URISyntaxException e2) {
        e2.printStackTrace();
    } 
    

提交回复
热议问题