简体   繁体   中英

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

Ok so i have this rather simple code although it keeps giving me this error message. I have tried various different solutions through google but i cannot seem to figure it out. I show where the error message is happening.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*; 
import java.lang.*;

public class Project4 extends JFrame
{


    private JLabel InCDAmount, YearTMature, CDInRate, EndBalance;

    private JTextField InCDAmountTF, YearTMatureTF, CDInRateTF, EndBalanceTF;

    private JButton calculateB, exitB;

    private CalculateButtonHandler cbHandler;
    private ExitButtonHandler ebHandler;

    private static int WIDTH = 400;
    private static int HEIGHT = 300;

    public Project4()
    {
    InCDAmount = new JLabel("Initial CD Amount", SwingConstants.LEFT);

    YearTMature = new JLabel("Years to Maturity", SwingConstants.LEFT);

    CDInRate = new JLabel("CD Intrest Rate", SwingConstants.LEFT);

    EndBalance = new JLabel("Ending Balance", SwingConstants.LEFT);


    InCDAmountTF = new JTextField(10);
    YearTMatureTF = new JTextField(10);
    CDInRateTF = new JTextField(10);

    calculateB = new JButton ("Calculate");
    cbHandler = new CalculateButtonHandler();
    calculateB.addActionListener(cbHandler);

    exitB = new JButton("Exit");
    ebHandler = new ExitButtonHandler();
    exitB.addActionListener(ebHandler);

    setTitle("ACME Bank Certificate Of Deposit Calculator");

    Container pane = getContentPane();

    pane.setLayout(new GridLayout(5, 2));

    pane.add(InCDAmount);
    pane.add(InCDAmountTF);
    pane.add(YearTMature);
    pane.add(YearTMatureTF);
    pane.add(CDInRate);
    pane.add(CDInRateTF);
    pane.add(EndBalance);
    pane.add(EndBalanceTF);

    setSize(WIDTH, HEIGHT);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }

  private class CalculateButtonHandler implements ActionListener
  {
     public void actionPerformed(ActionEvent e)
     {
     double InCDAmount, YearTMature, CDInRate, EndBalance;

     InCDAmount = Double.parseDouble(InCDAmountTF.getText());
     YearTMature = Double.parseDouble(YearTMatureTF.getText());
     CDInRate = Double.parseDouble(CDInRateTF.getText());
     EndBalance = InCDAmount + YearTMature + CDInRate;

     EndBalanceTF.setText("" + EndBalance);
     }
  }

Right here is where i am having the issue.

  private class ExitButtonHandler implements ActionListener

it gives me the error message

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

private class ExitButtonHandler implements ActionListener
{
     public void actionPreformed(ActionEvent e)
     {
        System.exit(0);
     }

     public static void main(String[] args)
     {
        Project4 rectObject = new Project4();
     }
}

You have a typo

public void actionPreformed(ActionEvent e)
                   ^^

should be changed to

public void actionPerformed(ActionEvent e)

Next time, the use of the annotation @Override may help you with these kind of issues.

@Override
public void actionPerformed(ActionEvent e)

It'll throw an error if the method is not a correct override.

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