javafx fxml获取识别不到controller里的方法
fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="266.0" prefWidth="332.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="sample.Controller">
<children>
<Button fx:id="myButton" layoutX="14.0" layoutY="53.0" mnemonicParsing="false"
onAction="#showtime" text="显示时间" />
<TextField fx:id="myTextField" layoutX="86.0" layoutY="53.0" />
</children>
</AnchorPane>
controller
package sample;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Controller {
@FXML
private Button myButton;
@FXML
private TextField myTextField;
@FXML
public void showtime(ActionEvent event) {
System.out.println("button clicked");
Date now = new Date();
DateFormat df = new SimpleDateFormat("yyyy-dd-MM HH:mm:ss");
String dateTimeString = df.format(now);
myTextField.setText(dateTimeString);
}
}
button中的onAction="#showtime"一直显示错误,求解。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ActionEvent event 要导入import javafx.event.ActionEvent,不是import java.awt.event.ActionEvent;