user3768356
user3768356

Reputation: 107

ActionListener is not abstract and does not override abstract method, but i have a actionPerformed, what is wrong?

I am writing a java program for my OOP class, and i am trying to add some actionlisteners, but for some reason i keep getting this error "BattleshipUI.ExitListener is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener", the following code is how i have my actionlistener constructed.

public class ExitListener implements ActionListener {
    public void actionPerformed(ActionEvent e){
        int response = JOptionPane.showConfirmDialog(null,"Are you sure you want to exit?","Exit",JOptionPane.YES_NO_OPTION);

        if (response == JOptionPane.YES_OPTION){
            System.exit(0);
        }
    }


}

I have about 4 of these in my code and i am getting the same error on each one. Any help would be much appreciated.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import javafx.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;

Upvotes: 0

Views: 4185

Answers (1)

Jean-François Savard
Jean-François Savard

Reputation: 21004

Change javafx.event.ActionEvent to java.awt.event.ActionEvent in your import or change

public void actionPerformed(ActionEvent e){
        int response = JOptionPane.showConfirmDialog(null,"Are you sure you want to exit?","Exit",JOptionPane.YES_NO_OPTION);

        if (response == JOptionPane.YES_OPTION){
            System.exit(0);
        }
    }

to

public void actionPerformed(java.awt.event.ActionEvent e){
        int response = JOptionPane.showConfirmDialog(null,"Are you sure you want to exit?","Exit",JOptionPane.YES_NO_OPTION);

        if (response == JOptionPane.YES_OPTION){
            System.exit(0);
        }
    }

if you need to keep the javafx import.

Upvotes: 3

Related Questions