0

我正在开发一个需要从此 URL 加载 fxml 源的 JavaFX 程序:http://pastebin.com/raw.php?i=SW5d5ucs

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="201.0" prefWidth="299.0" style="-fx-background-color: #2B2B2B;" fx:controller="aio_pkhonor.core.ui.crafting.CraftingInterfaceController" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label alignment="CENTER" layoutX="6.0" layoutY="6.0" prefHeight="51.0" prefWidth="291.0" text="Gem Crafting" textFill="WHITE">
<font>
<Font name="Rod" size="28.0"/>
</font>
</Label>
<Button fx:id="StartButton" layoutX="15.0" layoutY="162.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="273.0" style="-fx-background-color: #1b1b1b;" text="Start Script" textFill="WHITE"/>
<Label layoutX="28.0" layoutY="120.0" text="Gem To Craft : " textFill="WHITE"/>
<ComboBox fx:id="GemComboBox" layoutX="108.0" layoutY="116.0" prefHeight="25.0" prefWidth="163.0" promptText="Select Gem"/>
<RadioButton fx:id="AutoTrainButton" layoutX="24.5439453125" layoutY="57.0" mnemonicParsing="false" text="AutoTrain (Trains Your Acc To 2Bil XP)" textFill="WHITE">
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="CustomTrainButton" layoutX="25.0" layoutY="84.0" mnemonicParsing="false" text="Custom" textFill="WHITE" toggleGroup="$group"/>
</children>
</AnchorPane>

我已经尝试了一些东西,但似乎无法弄清楚,如果有人可以帮助我,那就太好了。

4

1 回答 1

1

假设您的类路径上有控制器,您可以这样做

import java.net.URL;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class RemoteFXMLTest extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(new URL("http://pastebin.com/raw.php?i=SW5d5ucs"));
        Scene scene = new Scene(root, 600, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

或者您可以复制代码,将其保存到 FXML 文件中,然后以标准方式使用它...

于 2014-08-23T19:41:32.887 回答