我想在我的Controller
类
只是一个错误,它告诉我它找不到方法
这是代码
sample.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="sample.Controller">
<children>
<Button layoutX="126" layoutY="90" text="lololol" onAction="#test" fx:id="button" />
</children>
</AnchorPane>
和Controller.java
package sample;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import java.awt.event.ActionEvent;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable
{
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
{
}
@FXML
private void test(ActionEvent event)
{
System.out.println("lollolol");
}
}
答案 0 :(得分:40)
替换:
import java.awt.event.ActionEvent;
使用:
import javafx.event.ActionEvent;