gpt4 book ai didi

java - 将ActionListener 添加到JMenuItem 时出错

转载 作者:行者123 更新时间:2023-12-01 23:56:02 25 4
gpt4 key购买 nike

required: ActionListener
found: EditMenuFunctions
reason: actual argument EditMenuFunctions cannot be converted to ActionListener by method invocation conversion

.\AFrame.java:56: error: method addActionListener in class AbstractButton cannot be applied to given types;

refMenuBar.time_date.addActionListener(new EditMenuFunctions());

AMenuBar refMenuBar = new AMenuBar();
protected final JMenuItem time_date = new JMenuItem("Time / Date");
refMenuBar.time_date.addActionListener(new EditMenuFunctions());

class EditMenuFunctions 是我的类,其中包含 actionPerformed() 方法。我将 actionListener 添加到 class AFrame 中的 JMenuItem,并在 class AMenuBar

中创建了 JMenuItem

最佳答案

您的EditMenuFunctions必须实现ActionListener。例如:

public class EditMenuFunctions implements ActionListener {

@Override
public void actionPerformed(ActionEvent event) { ... }

}

关于java - 将ActionListener 添加到JMenuItem 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15602325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com