SORU
10 HAZİRAN 2012, Pazar


Java düğmesi ile tarayıcıda bir bağlantı açın?

Nasıl çizgisinde bir butona tıklama ile varsayılan tarayıcıda bir bağlantı açın

button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        open("www.google.com"); // just what is the 'open' method?
    }
});

?

CEVAP
10 HAZİRAN 2012, Pazar


Desktop#browse(URI) yöntemi kullanın. Kullanıcının varsayılan tarayıcıda bir URI açar.

public static void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(uri);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

public static void openWebpage(URL url) {
    try {
        openWebpage(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • adrianisen

    adrianisen

    25 Kasım 2009
  • Malwarebytes

    Malwarebytes

    22 Temmuz 2007
  • TheFlashCentre

    TheFlashCent

    22 Mayıs 2008