Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java-为什么我会得到;类不是抽象的,并且不重写抽象方法;使用gui创建ATM时?_Java_Swing - Fatal编程技术网

java-为什么我会得到;类不是抽象的,并且不重写抽象方法;使用gui创建ATM时?

java-为什么我会得到;类不是抽象的,并且不重写抽象方法;使用gui创建ATM时?,java,swing,Java,Swing,制作一台有取款和存款选择的自动取款机。我包括了代码的缩写版本,我确实有其他ATM功能的按钮,但在发布时忽略了它。我还省略了带有尺寸/格式的部分 public class ATM extends JPanel implements ActionListener { private JButton withdraw1, withdraw2, deposit; private JLabel displayInput, instructions; private JPanel but

制作一台有取款和存款选择的自动取款机。我包括了代码的缩写版本,我确实有其他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) {
然后,我就有了所有的代码,知道单击每个按钮时该做什么。以下是我得到的错误:

java:6:错误:ATM不是抽象的,并且不会覆盖ActionListener中的抽象方法actionPerformed(ActionEvent) 公共类ATM扩展JPanel实现ActionListener{ ^
如何修复此错误?

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

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


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

您的
ATM
类未实现
ActionListener
合同的要求(您的
按钮Listener
正在执行此操作)。看一看并了解更多细节。我有点困惑…是否会是:abstract actionPerformed(ActionEvent buttonClicked)?@xson,您收到了一个链接,指向关于
如何编写ActionListener
(在对您的提问的评论中)的Swing教程。因此,请阅读该教程以获得一个工作示例。您应该删除从ATM类中“实现ActionListener”,或者以其他方式实现该方法(实际上需要编写方法代码)。