首页javaapplicationJavaFX - 如何在默认系统浏览器中加载URL

JavaFX - 如何在默认系统浏览器中加载URL

我们想知道如何在默认系统浏览器中加载URL。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage stage) {
    String yahooURL = "http://www.w3cschool.cn";
    Button openURLButton = new Button("Go!");
    openURLButton.setOnAction(e -> getHostServices().showDocument(yahooURL));

    Scene scene = new Scene(openURLButton);
    stage.setScene(scene);
    stage.setTitle("Knowing the Host");
    stage.show();
  }
}