【发布时间】:2017-08-22 13:11:10
【问题描述】:
您好,我目前正在为我的工作开发一个 PIN 生成器,由于我对 Java 完全陌生,我遇到了一些困难,尤其是在使用 JavaFX 时。 我想让程序在单击每个按钮时显示另一个 .fxml 文件。
这是我的代码:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class main extends Application {
public static void main(String[] args) {
Application.launch(main.class, args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/view/main.fxml"));
stage.setTitle("PIN-Generator");
stage.setScene(new Scene(root, 600, 400));
stage.show();
}
}
我为场景中的每个按钮创建了一个控制器类。
控制器类代码:
package view;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class MainController {
@FXML
private Label dpmadirektpropingenerator;
@FXML
private Button unlockPinButton;
@FXML
private Button confirmationPinButton;
}
【问题讨论】:
-
这是一个关于同一问题的答案,它可能会有所帮助:stackoverflow.com/questions/27160951/…