View.Listener is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javafx.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class View extends JFrame{

    JTextField tField = new JTextField(10);
    JButton sortButton = new JButton("Sort");
    JButton shuffleButton = new JButton("Shuffle");
    JButton reverseButton = new JButton("Reverse");
    JTextArea tArea = new JTextArea();
    JLabel label = new JLabel("Enter a number: ");
    JPanel upperPanel = new JPanel();
    JPanel buttonPanel = new JPanel();



    public View(){



        setTitle("Exercise 22.2");
        setSize(500,150);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);        
        setLayout(new BorderLayout());

        sortButton.addActionListener(new Listener());


        upperPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        upperPanel.add(label);
        upperPanel.add(tField);       

        buttonPanel.add(sortButton);
        buttonPanel.add(shuffleButton);
        buttonPanel.add(reverseButton);

        add(upperPanel, BorderLayout.NORTH);
        add(tArea, BorderLayout.CENTER);
        add(buttonPanel, BorderLayout.SOUTH);


    }

    /*Getting error here!*/
    public class Listener implements ActionListener{
        @Override        
        public void actionPerformed(ActionEvent e)
        {
            System.out.println("Hello");
        }
    }
}

I'm trying to create a class that implements ActionListener to that I can register the class to my buttons.

I'm getting: View.Listener is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener

I've tried implementing as an Anonymous Class and get the same error. I cannot figure it out.

Answers


I relied on auto imports and it imported the wrong library for ActionEvent.

import javafx.event.ActionEvent;

I needed import:

java.awt.event.ActionEvent;

My bad.


Need Your Help

Unit testing messages

c# unit-testing messages

I have a web page that shows different messages according to different conditions.

Applescript - Close Pages Document Automatically

applescript

I am trying to create a script that will automatically close the frontmost window of Apple Pages.