ExitButtonHandler不是抽象的,并且不会在ActionListener中覆盖抽象方法actionPerformed(ActionEvent)

时间:2016-03-22 19:42:27

标签: java

好的,所以我有这个相当简单的代码,虽然它一直给我这个错误信息。我通过谷歌尝试了各种不同的解决方案,但我似乎无法弄明白。我会显示错误消息的发生位置。

@RequestMapping(value = "/status")
@ResponseBody
public String fetchStatus() {
    --> Here return itRunning
}   

这就是我遇到问题的地方。

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);
     }
  }

它给了我错误信息

ExitButtonHandler不是抽象的,并且不会覆盖ActionListener中的抽象方法actionPerformed(ActionEvent)

  private class ExitButtonHandler implements ActionListener

1 个答案:

答案 0 :(得分:1)

你有一个错字

public void actionPreformed(ActionEvent e)
                   ^^

应改为

public void actionPerformed(ActionEvent e)

下次使用注释@Override可能会帮助您解决这些问题。

@Override
public void actionPerformed(ActionEvent e)

如果方法不是正确的覆盖,则会抛出错误。