Итак, у меня есть этот довольно простой код, хотя он продолжает давать мне это сообщение об ошибке. Я пробовал различные решения через Google, но я не могу понять, как это понять. Я показываю, где происходит сообщение об ошибке.ExitButtonHandler не является абстрактным и не переопределяет абстрактный метод actionPerformed (ActionEvent) в ActionListener
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);
}
}
Именно здесь у меня возникла проблема.
private class ExitButtonHandler implements ActionListener
это дает мне сообщение об ошибке
ExitButtonHandler не является абстрактным и не переопределяет абстрактный метод actionPerformed (ActionEvent) в ActionListener
private class ExitButtonHandler implements ActionListener
{
public void actionPreformed(ActionEvent e)
{
System.exit(0);
}
public static void main(String[] args)
{
Project4 rectObject = new Project4();
}
}
Сообщение об ошибке кажется настолько ясным, насколько возможно. Вы не переполняете actionPerformed –