gpt4 book ai didi

java- 为什么我在使用 gui 创建 ATM 时收到 "class is not abstract and does not override abstract method"?

转载 作者:行者123 更新时间:2023-12-01 11:03:22 26 4
gpt4 key购买 nike

制作具有取款和存款选项的 ATM。我包括了代码的缩短版本,我确实有其他 ATM 功能的按钮,但省略了它来发布。我还省略了带有尺寸/格式的部分。

public class ATM extends JPanel implements ActionListener {
private JButton withdraw1, withdraw2, deposit;
private JLabel displayInput, instructions;
private JPanel buttonPanel;



public ATM() {
withdraw1 = new JButton("Withdraw $20");
withdraw1.addActionListener(this);
withdraw2 = new JButton("Withdraw $40");
withdraw2.addActionListener(this);
deposit = new JButton("Deposit");
deposit.addActionListener(this);

}
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent buttonClicked) {

然后,我就拥有了单击每个按钮时要执行的操作的所有代码。这是我收到的错误:

ATM.java:6: 错误:ATM 不是抽象的,并且不会重写 ActionListener 中的抽象方法 actionPerformed(ActionEvent)公共(public)类 ATM 扩展 JPanel 实现 ActionListener { ^我该如何修复这个错误?

最佳答案

您应该实现抽象方法:actionPerformed(ActionEvent)

每当类实现接口(interface)时,它必须为接口(interface)中的所有方法提供实现。

另一种选择是从 ATM 类中删除“implements ActionListener”。

关于java- 为什么我在使用 gui 创建 ATM 时收到 "class is not abstract and does not override abstract method"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33160168/

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