简体   繁体   English

类不是Abstract吗?

[英]Class is not Abstract?

private class HandlerClass implements ActionListener
    {
        public void actionPerfomed(ActionEvent event)
        {
            JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand));
        }
    }

This is part of my code and when I compile, I get an error saying HandlerClass is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener . 这是我的代码的一部分,当我编译时,出现错误消息HandlerClass不是抽象的,并且没有覆盖actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener抽象方法actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener To my understanding, actionPerformed should override HandlerClass shouldn't it? 据我了解, actionPerformed应该覆盖HandlerClass ,不是吗? I already tried adding " abstract " before the word class but then I get another error since I can't call an abstract class. 我已经尝试在单词类之前添加“ abstract ”,但是由于无法调用抽象类,因此又出现了另一个错误。 I'm not sure if maybe there's an exception I can use to solve this? 我不确定是否可以使用例外来解决此问题?

Basically, you have a spelling mistake... 基本上,您有一个拼写错误...

actionPerfomed

Should be 应该

actionPerformed
           ^---- ;)

You may also want to use the @Override annotation which will tell you when you're attempting to override a method that doesn't exist in the parent classes... 您可能还想使用@Override批注,当您尝试覆盖父类中不存在的方法时,它将通知您。

@Override
public void actionPerformed(ActionEvent event)
{
    JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM