简体   繁体   中英

Select is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener

I have tried all the possibilities but the error still appears:

select.java:4: error: Select is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Select extends JFrame implements ActionListener
{
    JButton admin;
    JButton user;
JPanel panel;
public Select()
{
    admin=new JButton("admin");
    user=new JButton("user");
    panel=new JPanel(new GridLayout(3,1));
    panel.add(admin);
    panel.add(user);
    //admin.addActionListener();
    admin.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent a) {
            Login page=new Login();
            page.setVisible(true);
        }
    });
    user.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent b) {
            Login page=new Login();
            page.setVisible(true);
        }
    });
}
}
   class selection
    {
        public static void main(String arg[])
         {
            try
            {
                Select frame=new Select();
                frame.setSize(300,200);
                frame.setVisible(true);
            }
            catch(Exception e)
            {
                JOptionPane.showMessageDialog(null, e.getMessage());
            }
        }   
    }

You are using anonymous classes as action listeners for user and admin . You aren't using Select as an action listener, so simply remove the implements ActionListener from the declaration of class Select .

Alternatively, add the required method to Select :

class Select extends JFrame implements ActionListener {
    ...

    public void actionPerformed(ActionEvent e) {
        ...
    }
}

However, from the code you posted, there is no need for Select to implement ActionListener .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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