0

所以我正在做一个宠物项目,本质上是一本自己动手的角色扮演冒险书的数字化。

我切换到使用 Scenebuilder 是因为它在制作 GUI 时允许的自由度。我无法将数据绑定到屏幕。看来我调用的对象要么停止存在,要么不是我需要的对象。

我正在为我的数据使用 SQLite 数据库,这似乎工作正常。我正在使用 Maven 导入我需要的东西,这似乎也可以正常工作,但这需要我使用

public class DdAppLauncher {
    public static void main(String[] args) {
        DdApp2.main(args);
    }
}

进入->

public class DdApp2 extends Application {


    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/mainWindow.fxml"));


        stage.setTitle("Deathtrap Dungeon");
        stage.setScene(new Scene (root, 800,600));
        stage.show();

    }

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

    }
}

这会调出包含由以下控制器处理的开始按钮的标题屏幕。

public class MainController {

    LocationsPool loc;
    Location currentLocation;

    @FXML
    private ListView<String> inventory;

    @FXML
    private Text locationDescription;

    @FXML
    private Text descrA;
    @FXML
    private Text descrB;
    @FXML
    private Text descrC;
    @FXML
    private Text descrD;
    @FXML
    private Text descrE;
    @FXML
    private Text descrF;


    @FXML
    public void startButtonClicked(ActionEvent event){

        try {
            System.out.println("Starting game");
            Stage stage = (Stage) ((Node)event.getSource()).getScene().getWindow();

            // Swap screen
            Parent root = FXMLLoader.load(getClass().getResource("/fxml/gameWindow.fxml"));
            stage.setScene(new Scene(root,800,600));
        } catch (IOException e) {
            e.printStackTrace();
        }

        //Setup
        loc = new LocationsPool();
        currentLocation = loc.getLocation(1);


        System.out.println(currentLocation.getDescription());

        locationDescription = new Text(currentLocation.getDescription());
        System.out.println(locationDescription.getText());
        System.out.println(locationDescription);

    }


    @FXML
    public void handleButtonA(){
        System.out.println(currentLocation==null);

    }
}

控制台输出 -> 开始游戏

喧嚣……(作品)

喧嚣……(作品)

按下按钮 - >

真的

所以看起来应用程序在运行时“忘记”了字段?还是控制器停止存在并重新制作?

此外,当尝试使用 fx:id 将数据绑定到字段时,在我按下该按钮之前,它似乎不会将这些字段链接到任何内容。

我的结构错了吗?我没有得到什么?最终产品应加载描述并为该位置加载所有选项。然后在一个选择上应该加载一个新的位置和新的选择,所以需要更新文本。

提前致谢。凯夫

4

0 回答 0