栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

FXML文件中的getHostServices()。showDocument()

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

FXML文件中的getHostServices()。showDocument()

您需要将传递

HostServices
Controller

密码:在

HostServices
中设置
Controller

HostServices hostServices ;public void setGetHostController(HostServices hostServices){    this.hostServices = hostServices;}

密码:传递

HostServices
Controller

FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLdocument.fxml"));Parent root = loader.load();FXMLdocumentController fXMLdocumentController = loader.getController();fXMLdocumentController.setGetHostController(getHostServices());

主要

import javafx.application.Application;import javafx.fxml.FXMLLoader;import javafx.scene.Parent;import javafx.scene.Scene;import javafx.stage.Stage;public class JavaFXApplication7 extends Application {    @Override    public void start(Stage stage) throws Exception {        FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLdocument.fxml"));        Parent root = loader.load();        FXMLdocumentController fXMLdocumentController = loader.getController();        fXMLdocumentController.setGetHostController(getHostServices());        Scene scene = new Scene(root);     stage.setScene(scene);        stage.show();    }        public static void main(String[] args) {        launch(args);    }}

控制者

import java.net.URL;import java.util.ResourceBundle;import javafx.application.HostServices;import javafx.event.ActionEvent;import javafx.fxml.FXML;import javafx.fxml.Initializable;import javafx.scene.control.Label;public class FXMLdocumentController implements Initializable {    HostServices hostServices;    @FXML    private Label label;    @FXML    private void handleButtonAction(ActionEvent event) {        hostServices.showdocument("www.google.com");    }    @Override    public void initialize(URL url, ResourceBundle rb) {        // TODO    }    public void setGetHostController(HostServices hostServices)    {        this.hostServices = hostServices;    }}

XML文件

<?xml version="1.0" encoding="UTF-8"?><?import java.lang.*?><?import java.util.*?><?import javafx.scene.*?><?import javafx.scene.control.*?><?import javafx.scene.layout.*?><AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication7.FXMLdocumentController">    <children>        <Button layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />        <Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" />    </children></AnchorPane>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497480.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号