Action上的Java FX fxml [英] Java FX fxml on Action

查看:142
本文介绍了Action上的Java FX fxml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制台中的控制器

中定义的按钮中添加方法只是一个错误告诉我它找不到方法

in the console is only an error which tells me that it couldn't find the method

这里是代码

样本.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

and the 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");
    }
}


推荐答案

替换:

import java.awt.event.ActionEvent;

with:

import javafx.event.ActionEvent;

这篇关于Action上的Java FX fxml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆