FXML基础

这玩意挺好玩的,就跟写HTML一样(本来就是XML语言么)。

第一点:

 The XML processing instructions at the top of the file
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.Group?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Text?>
inform the consumer of this file, either JavaFX SceneBuilder at design,time or FXMLLoader at runtime, to import the mentioned Java classes.These have the same effect as import directives in Java source files.

在文件的顶部,处理了这些指令,目的是告诉这个文件的客户(使用者)--在设计阶段的SceneBuilder或者是在运行阶段的FXMLLoader,告诉他们包含了哪些JAVA类,这么翻译真别扭。

第二点:

Two namespace declarations are provided for the top-level element Group. JavaFX SceneBuilder puts these namespaces in every FXML file it creates:
xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1"

两个namespace declaration这是什么?名称空间声明??这个词专业术语咋说来着??

这俩玩意包含在顶级的元素Group中。

第三点:

This FXML file contains two kinds of attributes with the fx prefix,
fx:controller and fx:id. The fx:controller attribute
appears on the top-level element Group. It informs the JavaFX runtime that the UI designed in the current FXML file is meant to work together with a Java class called its controller:
fx:controller="projavafx.stagecoach.ui.StageCoachController

FXML以fx为前缀的包含两种类型的属性:fx:controller and fx:id

前者包含在顶级的元素Group中,这玩意告诉了在运行时的JavaFX,在当前FXML文件中,被设计好的UI是和一个叫做controller的java类一起工作的。我的理解就是前端和handler建立一种联系,就是声明他们的联系。后者fx:id在哪个节点属性里都可以用。The value of fx:id is the name of a field in the controller that represents the Node after the FXML file has been loaded.这句话目前还不太懂,字面看是这个ID是FXML文件加载后的controller域的名字。这一段估计得看到controller类的时候联系着看就能明白,做个记号先。在编程里field应该有一个单独的术语翻译,哪个大神留言告诉我一下。脑袋不够用,想不到怎么表达这个词了。看这句话:Thus after the FXMLLoader is done loading the FXML file, the top-level Group node in the FXML file can be accessed and manipulated in Java code as the rootGroup field of the StageCoachController class.因此,在FXMLLoader装载FXML文件完成后,这个顶级的Group node 就可以被java代码操作,作为....Controller类的field,这个field怎么翻译??怎么理解??引用?域变量?

第四点:

终于看到controller了。

Providing programmatic access to the nodes in an FXML file is one role that the controller plays. Another role the controller plays is to provide the methods that handle user input and interaction events originating from the nodes in an FXML file. These event handlers are specified by attributes whose name begins with “on”, such as onMouseDragged, onMousePressed, and onAction. They correspond to the setOnMouseDragged(),
setOnMousePressed(), and setOnAction() methods in the
Node classes or its subclasses. To set the event handlers to a method in the controller, use the method name preceded with a “#” character as the value of the onMouseDragged, onMousePressed, and onAction attributes. The StageCoach.fxml file declares the following event handlers (only lines with event handlers are shown):
<Group fx:id="rootGroup"
onMouseDragged="#mouseDraggedHandler"
onMousePressed="#mousePressedHandler"
<Button fx:id="toBackButton"
onAction="#toBackEventHandler"
<Button fx:id="toFrontButton"
onAction="#toFrontEventHandler"
<Button fx:id="closeButton"
onAction="#closeEventHandler"


这段话字面意思很好理解,但是有个问题,哪个是 controller??我理解为controller是一个 java类,这个类扮演两个角色,也就是起了两个作用,一个是提供操作FXML的接口,一个是提供处理方法,个人理解,不知道对不对。看到这里,还是没有接触到controller.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值