【发布时间】:2018-06-18 10:19:29
【问题描述】:
我正在用 JavaFXML 开发一个小型的假邮件客户端。 它提供了一个 Listview,其中包含写在 txt 文件中的消息、一个打印所选消息的 TextArea 和一些按钮。 这是主视图的图像:https://ibb.co/iKN2rm 我已经处理了“新消息”按钮,它正在启动一个新的 FXML 视图并且运行良好。
这是“New_Message”视图的图像:https://ibb.co/hQf5Bm
现在我正在尝试实现“回复”按钮,它应该启动与之前相同的视图(新消息),但设置从主视图获取的所有三个 TextFields 字符串,例如消息的文本、收件人和消息参数.
在新消息按钮处理程序下方:
private void handle_new(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/Client/Resources/new_utente1.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("New Message");
stage.setScene(new Scene(root1));
stage.show();
} catch (Exception ecc) {
System.out.println("ERROR: " + ecc.getMessage());
}
}
我尝试实现 handle_reply 方法,但我无法添加参数,因为如果我这样做,FXML 文件将找不到该方法。
在 FXML 文件的一小部分下方:
<TextArea fx:id = "testo" editable="false" layoutX="283.0" layoutY="53.0" prefHeight="450.0" prefWidth="490.0" promptText="Select a message and it will be displayed here..." />
<Button id="nuovo" layoutX="46.0" layoutY="521.0" onAction = "#handle_new" mnemonicParsing="false" prefHeight="25.0" prefWidth="173.0" text="New Message" />
<Button id="reply" layoutX="283.0" layoutY="521.0" onAction = "#handle_reply" mnemonicParsing="false" prefHeight="25.0" prefWidth="132.0" text="Reply" />
我的问题是:如何实现前面描述的“handle_reply”方法? 谢谢
【问题讨论】:
-
您可以从控制器中的文本字段和pass them to the new fxml's controller 中获取这些值。