Java Error: Class 'Anonymous' must either be declared abstract or implement abstract method 'actionPerformed(ActionEvent)' in 'ActionListener'

TheCorey28

I've been struggling to setup an action listener for a button, and I can't figure out why. I've referred to many tutorials, but I've been getting the must be declared abstract or must implement abstract method ..... error. I've seen similar topics about fixing this, but nothing that really helped me out. Any help would be great. Here is a short example that is similar to what I am doing:

import java.awt.event.ActionListener;
import javafx.event.ActionEvent;
import javax.swing.*;


public class Kitty {

    private static void mainFrame() {

        JFrame mainFrame = new JFrame("Kitty");
        JPanel mainPanel = new JPanel();
        mainFrame.setSize(200,200);
        mainFrame.setResizable(false);
        mainFrame.add(mainPanel);
        mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        mainFrame.setVisible(true);

        JButton button1 = new JButton("Pet the kitty");
        mainPanel.add(button1);

        button1.addActionListener(new ActionListener(){
        // Line above (Specifically ActionListener) says Class 'Anonymous' must either be declared abstract or
        // implement abstract method 'actionPerformed(ActionEvent)' in 'ActionListener'

            public void actionPerformed(ActionEvent event){
                System.out.println("Purrrrrr....");
            }
        });
    }

    public static void main(String[] args) {
        mainFrame();
    }
}
wvdz

You imported the wrong ActionEvent class. Thtat's why it's saying you didn't implement that method. Use java.awt.event.ActionEvent.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java Error: Class 'Anonymous' must either be declared abstract or implement abstract method 'actionPerformed(ActionEvent)' in 'ActionListener'

From Dev

Class must either be declared abstract or implement abstract method error

From Dev

Class must either be declared abstract or implement abstract method: Intellij error?

From Dev

RxAndroid: Class must either be declared abstract or implement abstract method error

From Dev

Class must either be declared abstract or implement abstract method: Intellij error?

From Dev

Class must either be declared abstract or implement abstract method

From Dev

Class must either be declared abstract or implement abstract method?

From Dev

Class must be declared as abstract or implement abstract method

From Dev

Android: Class 'MainActivity2' must either be declared abstract or implement abstract method 'onNothingSelected(AdapterView<?>'

From Dev

Declared as an inner class but error "must be declared abstract or implement" persists

From Dev

Class SubList() must either be called abstract or implement abstract method 'listIterator' in 'List'

From Dev

"Class contains 1 abstract method so must be declared abstract or implement the remaining methods (parent::hasErrors)"

From Dev

parse anonymous class does not implement abstract method

From Dev

Error: "class must implement abstract method X", but it already does

From Dev

Class CI_Session_files_driver contains 1 abstract method and must therefore be declared abstract or implement the remaining methods

From Dev

Error: anonymous class is not abstract and does not override abstract method

From Dev

<AdapterClass> either be declared abstract or implement abstract method onBindViewHolder(VH,int) in <AdapterClass>

From Dev

Abstract Method In Abstract Class In java

From Dev

Method issue Java GUI - must implement the inherited abstract method

From Dev

onBindViewHolder must be declared abstract

From Dev

Java Class extends Abstract class but must have static method

From Dev

Java Class extends Abstract class but must have static method

From Dev

AWT ActionListener as abstract class

From Dev

Java child class not able to implement parent class's abstract method

From Dev

Class is not abstract and does not override abstract method error

From Dev

Android must implement the inherited abstract method

From Dev

the type must implement the inherited abstract method

From Dev

calling non abstract method in abstract class java

From Dev

Extending abstract method with generic parameter (that must extend generic class) in Java

Related Related

  1. 1

    Java Error: Class 'Anonymous' must either be declared abstract or implement abstract method 'actionPerformed(ActionEvent)' in 'ActionListener'

  2. 2

    Class must either be declared abstract or implement abstract method error

  3. 3

    Class must either be declared abstract or implement abstract method: Intellij error?

  4. 4

    RxAndroid: Class must either be declared abstract or implement abstract method error

  5. 5

    Class must either be declared abstract or implement abstract method: Intellij error?

  6. 6

    Class must either be declared abstract or implement abstract method

  7. 7

    Class must either be declared abstract or implement abstract method?

  8. 8

    Class must be declared as abstract or implement abstract method

  9. 9

    Android: Class 'MainActivity2' must either be declared abstract or implement abstract method 'onNothingSelected(AdapterView<?>'

  10. 10

    Declared as an inner class but error "must be declared abstract or implement" persists

  11. 11

    Class SubList() must either be called abstract or implement abstract method 'listIterator' in 'List'

  12. 12

    "Class contains 1 abstract method so must be declared abstract or implement the remaining methods (parent::hasErrors)"

  13. 13

    parse anonymous class does not implement abstract method

  14. 14

    Error: "class must implement abstract method X", but it already does

  15. 15

    Class CI_Session_files_driver contains 1 abstract method and must therefore be declared abstract or implement the remaining methods

  16. 16

    Error: anonymous class is not abstract and does not override abstract method

  17. 17

    <AdapterClass> either be declared abstract or implement abstract method onBindViewHolder(VH,int) in <AdapterClass>

  18. 18

    Abstract Method In Abstract Class In java

  19. 19

    Method issue Java GUI - must implement the inherited abstract method

  20. 20

    onBindViewHolder must be declared abstract

  21. 21

    Java Class extends Abstract class but must have static method

  22. 22

    Java Class extends Abstract class but must have static method

  23. 23

    AWT ActionListener as abstract class

  24. 24

    Java child class not able to implement parent class's abstract method

  25. 25

    Class is not abstract and does not override abstract method error

  26. 26

    Android must implement the inherited abstract method

  27. 27

    the type must implement the inherited abstract method

  28. 28

    calling non abstract method in abstract class java

  29. 29

    Extending abstract method with generic parameter (that must extend generic class) in Java

HotTag

Archive