我正在关注此页面为 Javafx 2 提供的教程:
http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm
我的 fxml 代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.*?>
<GridPane gridLinesVisible="false" hgap="10.0" vgap="10.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<fx:script>
function handleSubmit() {
actionTarget.setText("Calling the Javascript");
}
</fx:script>
<children>
<Text text="Welcome" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0" GridPane.rowSpan="1" />
<Label text="Username" GridPane.columnIndex="0" GridPane.rowIndex="1" />
<Label text="Password" GridPane.columnIndex="0" GridPane.rowIndex="2" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<PasswordField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<HBox alignment="BOTTOM_RIGHT" GridPane.columnIndex="1" GridPane.rowIndex="4">
<children>
<Button onAction="handleSubmit(event);" text="Sign In" />
</children>
</HBox>
<Text fx:id="actionTarget" GridPane.columnIndex="1" GridPane.rowIndex="6" />
</children>
<padding>
<Insets bottom="25.0" left="25.0" right="25.0" top="25.0" />
</padding>
</GridPane>
但是每当我单击按钮时,我都会收到错误消息:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: javax.script.ScriptException: ReferenceError: "handleSubmit" is not defined in <eval> at line number 1
Caused by: javax.script.ScriptException: ReferenceError: "handleSubmit" is not defined in <eval> at line number 1
有人可以告诉我代码有什么问题吗?我在 Xubuntu 上使用 Oracle Java 8 JRE