我正在使用JavaFX制作游戏。上一次我更改代码成功了,但是当我回来时它不再起作用了。而且我无法用Scenebuilder打开特定的fxml文件。我可以双击该文件并进行编辑,但是SceneBuilder无法打开它。
我已经尝试过将项目文件夹添加到“编辑源查找路径”中 但它仍然没有用。 我还尝试复制fxml代码并将其粘贴到新的fxml文件中(删除旧的fxml文件后,我使用相同的名称制作)仍然无效
//MainApp.java
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("view/Start.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("TRPG");
primaryStage.setResizable(false);
primaryStage.show();
}
//MainPageController
MainApp ma = new MainApp();
@FXML
private AnchorPane mainpane;
@FXML
private Scene sc;
@FXML
private Label main;
@FXML
private Button Btn;
// primaryStage.setScene(scene);
public MainPageController() throws IOException {
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
mainpane.setOnKeyPressed(ke ->{
KeyCode keyCode = ke.getCode();
//System.out.println("asdf");
if(keyCode.equals(KeyCode.W)) {
Parent second;
try {
second = FXMLLoader.load(getClass().getResource("IngameScene.fxml"));
Scene scene = new Scene(second);
Stage primaryStage =(Stage) Btn.getScene().getWindow();
primaryStage.setScene(scene);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mainpane.getChildren().remove(Btn);
});
//Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="mainpane" prefHeight="800.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.makery.TRPG1.view.MainPageController">
<children>
<Label fx:id="main" layoutX="375.0" layoutY="270.0" prefHeight="242.0" prefWidth="189.0" text="Main" />
<Button fx:id="Btn" layoutX="350.0" layoutY="441.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>
//StartController
StartBtn.setOnMouseClicked( event -> {
System.out.println("Changed to MainPage.fxml");
try {
Parent second =FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(second);
Stage primaryStage =(Stage) StartBtn.getScene().getWindow();
primaryStage.setScene(scene);
// Stage sc =(Stage) StartBtn.getScene().getWindow();
//sc.getChildren()remove(ISC.AP);
} catch (IOException e) {
// TODO Auto-generated catch bloc"r
e.printStackTrace();
}
});
ExitBtn.setOnMouseClicked( event ->{
System.exit(0);
});
//Start
<AnchorPane prefHeight="800.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.makery.TRPG1.view.StartController">
<children>
<ImageView fitHeight="800.0" fitWidth="1280.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../../../illusts/Start.jpg" />
</image>
</ImageView>
<Button fx:id="ExitBtn" layoutX="510.0" layoutY="524.0" mnemonicParsing="false" prefHeight="60.0" prefWidth="300.0" text="Exit" />
<Button fx:id="StartBtn" layoutX="510.0" layoutY="419.0" mnemonicParsing="false" prefHeight="60.0" prefWidth="300.0" text="Start" />
</children>
</AnchorPane>
//MoveMenuController
@FXML
AnchorPane MovePane;
@FXML
Button Btn;
IngameSceneController ISC = new IngameSceneController();
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
Btn.setOnMouseClicked( event -> {
// AnchorPane root = (AnchorPane) Btn.getScene().getRoot();
//root.getChildren().remove(MovePane);
});
}
//MoveMenu
<AnchorPane fx:id="movePane" prefHeight="800.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.makery.TRPG1.view.MoveMenyController">
<children>
<Button fx:id="Btn" layoutX="146.0" layoutY="236.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>
Application.launch 它说没有找到来源
控制台 应用程序启动方法异常